Script to automatically create a series of predecesor linked records

634 2
Showing results for 
Search instead for 
Did you mean: 
5 - Automation Enthusiast
5 - Automation Enthusiast


I'm learning to run scripts and have been able to successfully write a couple of scripts for my work as a coach. 

I already know how to ask for the number of sessions (eg. ¿how many sessions?: 3) and then automatically create 4 records that are as follows: KickOff, Coaching1, Coaching2 and Coaching3. 

My difficulty is in how can I automatically create dependencies with linked records to the same table. So for example: Coaching1 has KickOff as predecesor, Coaching2 has Coaching1 as predecesor, Coaching3 has Coaching2 as predecesor.

Attached you can see a simplified table...

Table_Screenshot .png

The script I have up to now is:

//Create Table Variable
let TableCreateDependencies = base.getTable('CreateDependencies')

//Ask for Number of Sessions
let NumberOfSessions = await input.textAsync('¿How many sessions for this process?');

//Create KickOff
let CreateRegister = await TableCreateDependencies.createRecordsAsync([
"Activity": "KickOff",

//Create Selected Number of Sessions
for (let step=1; step<=NumberOfSessions; step++)
{let CreateRegister = await TableCreateDependencies.createRecordsAsync ([
"Activity": "Coaching"+step,
output.text(`End of Code`);
I appreciate the help... thanks.
2 Replies 2

Congrats on your progress in your coding journey!

Because you want to populate a linked record field with a record that you are also creating, you will need to create the records one at a time. When you create a new record, you get the record ID of the record just created. You then use that record ID to populate the linked record field of the next record you are creating. The format for a linked record field is in the scripting reference.

Hello Kuovonne,

Thanks for your help... I'm really new to scripting so please be patient with my basic questions :).... I think the link of 'create a new record' is something I'm already ok with, if you see my script I'm even creating multiple records with a 'for' function. 

Now I looked into the 2nd link you sent me... and I see that I need to have the RecordID and inserted in the 'recXXXXXX' part of the script. But because I'm creating the records in the same script, and I have multiple records being created I wouldn't be able to put a fixe RedordID by typing it...

I wonder how can I maybe walk in this way:

1. Create the record.
2. Capture the RecordID of 1st created record
3. Insert that RecordID on my 2nd record PredecesorField.

Again... thanks for your help.