Help

Re: Clear/Blank out Linked Field via Automated Script

1644 3
cancel
Showing results for 
Search instead for 
Did you mean: 

Hello all,

I’ve been updating a Record in a Linked Table to point to a different Main Record using the below code;

let _ins = input.config();

let main_table = base.getTable("Main Table");
let linked_table = base.getTable("Linked Table");

let main_rec    = _ins._get_record;
let linked_rec  = _ins._get_linked_record;
let linked_val  = _ins._get_linked_value;

console.log(`main_rec:   ${main_rec}`);
console.log(`linked_rec: ${linked_rec}`);
console.info(`linked_val: ${linked_val}`);

if (linked_val == "Not Listed") {
    console.warn("Not Listed - Clearing and rewriting entry");
        
    await linked_table.updateRecordAsync(`${linked_rec}`, {
        "Linked Text": `Example updated ${linked_table} record text`,
      //"Main"   : [{id:`${main_rec}`}] //Field is updated with expected record via recordID
        "Main"   : [{id:`${""}`}] //Attempt to clear field is not working...
        });
    console.info(`Updated Table "${linked_table.name}" record ${linked_rec} with "${main_rec}`);
};

This particular line of code works, updating an entry

//Field is updated with expected record via recordID
 "Main" : [{id:`${main_rec}`}] 

But what if I want to update the entry with a blank value, clear out the field for that record?

// Attempt to clear field is not working
"Main" : [{id:`${""}`}] 

I’ve tried null, undefined, and a few other ideas - none of which are executing. Keen for some help if anyone can spare a moment.

I’m also keen to rewrite my code with more direct calls. For example, although this works it makes me feel uneasy, and I’d like to know the preferred syntax;

    await linked_table.updateRecordAsync(`${linked_rec}`, {}

I’m sure I’m not to be using string literals for record ID lookups :joy: … yeah it works, no I’m not proud of it. Appreciate some pointers!

13 Replies 13

How are you setting the input variable _get_linked_record? Is it the result of a “Find Records” action or is it from a triggering record? What does typeof linked_rec produce? If linked_rec is a string, why not use the variable by itself?

It’s a mix of Automation input, but also record queries. This morning my previous JS learning finally “clicked” in my head of how to approach problems within Airtable scripts, and now I’m leveraging .filter and .map by chaining them together, and drawing data out of getCellValue etc.

//console.log(query.records.filter( record => (record.getCellValue("Numbers") == "0")).map( record => record.getCellValue("Important Note")));

It’s all coming back to me, just like riding a bike! Feels good. :smiling_face_with_sunglasses:

This looks suspicious to me. It looks like you are comparing the value of a number field with a text string, and the two would never be equal. If the “Numbers” field actually returns a text string that looks like a number, then it is badly named.

Yes, good spot. But it’s purposefully a string field filled with leading zero number entries that have a set/locked digit length. Aren’t inherited projects just the dandiest things?