Help

Attempting to create x new records linking to a different table based on user defined x

Topic Labels: Automations
Solved
Jump to Solution
3113 5
cancel
Showing results for 
Search instead for 
Did you mean: 
nefiger
6 - Interface Innovator
6 - Interface Innovator

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:

Screenshot 2023-01-26 at 10.23.09.png

 

 

 

 

 

 

This is the error:

Screenshot 2023-01-26 at 10.23.56.png

 And these are the details of the object:

Screenshot 2023-01-26 at 09.13.44.png

 Currently I suspect there's a type mismatch somewhere - but any help would be greatly appreciated! 

 

1 Solution

Accepted Solutions
TheTimeSavingCo
18 - Pluto
18 - Pluto

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

See Solution in Thread

5 Replies 5

Could you provide a screenshot of the relevant tables, or even better, a link to the base with dummy data please?

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)

I should note that the script is on dashboard 2

TheTimeSavingCo
18 - Pluto
18 - Pluto

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

@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.