Jan 26, 2023 12:30 AM
I'm a scripting newbie and need a little help...
I'm attempting to create a number of placement records, linking to a booking where the number of records is inputted by the user.
I've cobbled together pieces from various example scripts I've found, but I'm hitting an error. Please see details below.
This is the script:
This is the error:
And these are the details of the object:
Currently I suspect there's a type mismatch somewhere - but any help would be greatly appreciated!
Solved! Go to Solution.
Jan 26, 2023 05:39 AM
Thanks!
Could you try swapping the following:
for (let i = 0; i < Number(performers); i++ ) {
await placements.createRecordAsync([
{
fields: {
'Event ID': [{id: bookingId}]
},
}
])
console.log(i)
}
To this?
for (let i = 0; i < Number(performers); i++ ) {
await placements.createRecordAsync({
'Event ID': [{id: bookingId.id}]
})
console.log(i)
}
You were using the format for 'createRecordsAsync()' instead of 'createRecordAsync()'.
I would also recommend renaming 'bookingId' to 'bookingRecord' as the user selects the record at that point and not the id, which is why I modified the line to `[{id: bookingId.id}]` as well
Jan 26, 2023 01:22 AM
Could you provide a screenshot of the relevant tables, or even better, a link to the base with dummy data please?
Jan 26, 2023 01:39 AM
Hey @TheTimeSavingCo
Thanks so much for the response. Here's a link to the base.
(FYI: Since posting, I've changed the primary key on the joining table (Events people offerings) with a formula)
Jan 26, 2023 02:51 AM
I should note that the script is on dashboard 2
Jan 26, 2023 05:39 AM
Thanks!
Could you try swapping the following:
for (let i = 0; i < Number(performers); i++ ) {
await placements.createRecordAsync([
{
fields: {
'Event ID': [{id: bookingId}]
},
}
])
console.log(i)
}
To this?
for (let i = 0; i < Number(performers); i++ ) {
await placements.createRecordAsync({
'Event ID': [{id: bookingId.id}]
})
console.log(i)
}
You were using the format for 'createRecordsAsync()' instead of 'createRecordAsync()'.
I would also recommend renaming 'bookingId' to 'bookingRecord' as the user selects the record at that point and not the id, which is why I modified the line to `[{id: bookingId.id}]` as well
Jan 26, 2023 06:51 AM
@TheTimeSavingCo you are legendary - works like a charm! Such a silly error to have used the wrong format for the method.
I really appreciate the assistance, as well as the tip for bookingRecord. I'm still getting my head around literals following me through tables, rather than FKs.