Help

Re: Obtain Record ID - Using input.config

Solved
Jump to Solution
4938 0
cancel
Showing results for 
Search instead for 
Did you mean: 
Ryan_Banks
5 - Automation Enthusiast
5 - Automation Enthusiast

Dear Airtable Community,

I have created an automation that has multiple actions:

  1. Triggered by a webhook (beneficiary data comes in with various traits)

  2. Creates a new record in Table 1 with this new data as is (no manipulation)

  3. Runs a script that assigns a unique ID to beneficiary (based on this new record in step 2)

  4. Runs a script that assigns a household ID to beneficiary’s household (based on this new record in step 2)

  5. Runs a script that cleans record (created in step 2 with new assigned variables created in steps 3&4) and then creates a new record in Table 2

I have tested the scripts and they all run as expected - however, in steps 3 and 4 I use the .updateRecordAsync function:

Step 3:
var recordID = inputConfig.NewRecordID;
await tableRaw.updateRecordAsync(recordID,{“Household Member ID Generated”: idFinalString});

Step 4:
var recordID = inputConfig.NewRecordID;
await tableRaw.updateRecordAsync(recordID,{“Map Block Code”: codeBlock,“Household Unique ID” : HhUniqueID});

And in both cases I get the error: Could not find record with ID “rec…”

I have initialised the record ID to capture the Airtable record ID of the record created in step 2 using the input.config() variables in the left hand pane (as I have done for other variables where I get the expected value). But it seems that whenever I use input.config() to obtain the Airtable Record ID, I get a value that is not the expected record ID?

I have even searched through all the records in Table 1 manually by creating a new formula field using RECORD_ID() and comparing them to the record ID created using the input.config() method and did not find it.

Do you have any idea what I could be doing wrong? Is there a reason using the Input.config method to obtain the record ID of the record that initiated the whole automation would output an unexpected ID?

Cheers,
Ryan.

1 Solution

Accepted Solutions
Ryan_Banks
5 - Automation Enthusiast
5 - Automation Enthusiast

@Justin_Barrett Thanks for the reply.

The issue was that I was testing the script - and in that test a dummy RecordID is created, therefore the updateRecords function is not able to find that RecordID in the table. Once I let the script run it ran as expected.

Thanks for the assistance.

See Solution in Thread

5 Replies 5

Are you able to share screenshots of your “Run a script” automation actions, with the script open for editing so both the script and the input variable(s) can be clearly seen? There’s probably some detail that will solve this problem that’s not present in your description, and I’m guessing a look at the screenshots will help.

Ryan_Banks
5 - Automation Enthusiast
5 - Automation Enthusiast

Hi @Justin_Barrett,

Thanks for the response! I’ve posted the script below:

//Create Arrays for IDs, DOBs and Genders
var inputConfig = input.config();
var idArray = inputConfig.hhMembersIDs.split(“,”);
var dobArrayRaw = inputConfig.hhMembersDOBs.split(“,”);
var genderArray = inputConfig.hhMembersGenders.split(“,”);

//Clean DOB Array
var dobArray = new Array;
for(let i=0; i<dobArrayRaw.length; i++){
dobArray[i] = dobArrayRaw[i].trim().substring(0,10);
}

//Random Number generator (between values and inclusive)
function randomNumGenerator(min,max){
return Math.floor(Math.random()*(max - min +1) + min);
}

//Random Letter generator
function randomLetGenerator(){
var characters = ‘abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ’;
var charactersLength = characters.length;
return characters.charAt(Math.floor(Math.random()*charactersLength));
}

var idFinalArray = new Array;
var idFinalString = ‘’;
//Working with ID string in the following format: yymmddggggcaz
for(let i=0;i<idArray.length;i++){
if(idArray[i].match(“n/a”)){
//Extract yymmdd from DOB
var yy = dobArray[i].substring(2,4);
var mm = dobArray[i].substring(5,7);
var dd = dobArray[i].substring(8,10);
//Generate random number for gender
if(genderArray[i].match(“male”)){
var gggg = randomNumGenerator(5000,9999).toString().padStart(4,“0”);
}else{
var gggg = randomNumGenerator(0,4999).toString().padStart(4,“0”);
}
//c
var c = ‘0’;
//a
var a = randomLetGenerator();
//z
var z = Math.ceil(Math.random()).toString();
//Concat values
idFinalArray[i] = yy+mm+dd+gggg+c+a+z;
}else{
idFinalArray[i] = idArray[i].trim();
}
}

idFinalString = idFinalArray[0];
for(let i=1;i<idFinalArray.length;i++){
idFinalString += “,”+idFinalArray[i];
}

//Get table (rawdata) and most recently created record data to be able to update the data

var tableRaw = base.getTable(“census_data_raw”);

var recordID = inputConfig.NewRecordID;

var recordID_Formula = inputConfig.NewRecordID_Formula;

await tableRaw.updateRecordAsync(recordID,{“Household Member ID Generated”: idFinalString});

@Ryan_Banks Sorry for the delayed reply. I don’t think it’s the script that’s the problem. I think it’s something else with the configuration of the script actions. That’s why I asked to see screenshots showing how you configured the input variables for each script.

For future reference when sharing code in a post, I strongly recommend formatting it with the Preformatted Text option (click this icon in the toolbar after selecting the text to format: </> ). It makes the code much easier to decipher.

Ryan_Banks
5 - Automation Enthusiast
5 - Automation Enthusiast

@Justin_Barrett Thanks for the reply.

The issue was that I was testing the script - and in that test a dummy RecordID is created, therefore the updateRecords function is not able to find that RecordID in the table. Once I let the script run it ran as expected.

Thanks for the assistance.

Airtable doesn’t create dummy record IDs for testing. If a record ID is passed, it’s from a real record.

My guess is that the record that Airtable chose was available when the trigger was first tested, but was deleted before you began testing the script action. If that’s the case, then the record ID of the deleted record would still be passed through—even though it was no longer available—because it existed at the time of the trigger test. When testing automations, Airtable only verifies that previous steps have been tested successfully; it doesn’t (sadly) check to see if conditions have changed that might invalidate a previous test. Only by retesting the trigger to get a new valid record would you be certain that you have a valid record ID for later actions.