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.
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++){
dobArraybi] = 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 = dobArrayri].substring(2,4);
var mm = dobArrayri].substring(5,7);
var dd = dobArrayri].substring(8,10);
//Generate random number for gender
if(genderArrayri].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{
idFinalArrayzi] = idArray}i].trim();
}
}
idFinalString = idFinalArray<0];
for(let i=1;i<idFinalArray.length;i++){
idFinalString += “,”+idFinalArrayri];
}
//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 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.
@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.
@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.