Skip to main content
Solved

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

  • January 26, 2023
  • 5 replies
  • 44 views

nefiger
Forum|alt.badge.img+4

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! 

 

Best answer by TheTimeSavingCo

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

5 replies

TheTimeSavingCo
Forum|alt.badge.img+31

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


nefiger
Forum|alt.badge.img+4
  • Author
  • Participating Frequently
  • January 26, 2023

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)


nefiger
Forum|alt.badge.img+4
  • Author
  • Participating Frequently
  • January 26, 2023

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
Forum|alt.badge.img+31

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


nefiger
Forum|alt.badge.img+4
  • Author
  • Participating Frequently
  • January 26, 2023

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.