Help

Json problem with variable recordID

Topic Labels: API Scripting
1019 3
cancel
Showing results for 
Search instead for 
Did you mean: 
Jesper_Holmstro
6 - Interface Innovator
6 - Interface Innovator

Hi I have an automation script, and run into a problem, it is not fetching the right recordId in the script, but it does in the previous step. Anybody with a larger brain that can se what I have done wrong here?

All the Best
Jesper

3 Replies 3
Richard_Quintan
5 - Automation Enthusiast
5 - Automation Enthusiast

Hello there. I'm not sure if you trying to get a match between the recordID from the input and the recordID in the table called "Matsalen", but in any case, I tried to figure out this solution

let table = base.getTable("YOUR_TABLE_NAME");
let id = input.config().recordID.toString()
let query = await table.selectRecordsAsync({
    fields: ["Field1", "Field2",...,"Fieldn","RecordID"], //you should select all the records to display after the recordID match
})

let array = [] 

//Getting all the records from the table and pushing them into an object array
for (let record of query.records){
   array.push(
    {
      "id": record.getCellValueAsString("RecordID")
    }
   )
}

//Loop through the array to match the input recordID with the recordID in the table
for (var i=0; i<array.length;i++){
  if(array[i].id === id){
    console.log(`The ID of the input is ${id} and 
    it belongs to the record
    ${query.getRecord(id).getCellValue("Fieldn")} //Here you can choose the field or fields you would like to display with multiple getCellValue
    `)
  }
}

 Let me know if it's useful for your case. 

 

Regards.

Thanks @Richard_Quintan 

I solved it like this, the problem was it didn't pic the right recordID, but now it works on 1 automation

Pic1.png

 But I have now a problem when the variable is a "list of AirtableIDs" since its going to be a scheduled automation, but its always just going to be 1 recordID, but in the variable I can't choose just 1. And this code gives me syntax error. Do you know what I need to do in the script when there is a "list" of Airtable IDs but is always just going to be one?

Pic2.png

 You see the difference in the variable of the recordID on the left.

Hello there @Jesper_Holmstro and sorry for the delay in responding. As I'm watching, I think that you can't match with the exact ID due to the wrong usage of the function selectRecordsAsync(). In your particular case, you should do something like this

let table = base.getTable("YOUR_TABLE_NAME");

let query = await table.selectRecordsAsync({
    fields: ["Field1", "Field2",...,"Fieldn","RecordID"], //you should select all the records you want to retrieve, even the recordID field
})

To retrieve the recordID field correctly, you should create a field type formula and then write the formula 

RECORD_ID(). With that, you should be able to match the recordID from your input with the recordID in your table. 
 
Let me know if it works for you!