Skip to main content

I’m trying to delete a record if my function fails to find a match with the query.



//The Record ID I want to find a match for in the sourceTable

let recordIDsource = inputConfig.recordIDsource



// Find records in sourceTable

let query = await sourceTable.selectRecordsAsync({fields: :"Record ID"]});



//Select the records from the query with matching Record ID's

let recordTOupdate = query.getRecord(recordIDsource);



If there is a matching ID this works great and gives me the record ID of the record containing my matching “Record ID” in a field. (I know, confusing)



The problem is when there is not a matching “Record ID”, rather then giving me a value of null or undefined or 0. I launches an ERROR and breaks my script.





What I want to do is, if there are no matching record ID’s, I want to delete theRecord that triggered the automation in the first place.





if ( query.getRecord(recordIDsource) === Error ) {



await table.deleteRecordAsync(theRecord);



}



I know that code above " === Error " doesn’t work, it’s just an example of what I would want it to do…



Any help would mean a lot!



Thanks

Try something by like this …



let recordTOupdate = query.records.find(record => 

record.id == recordIDsource)


Reply