I'm having difficulty automating a task that I need for my database. Essentially what I'm trying to do is to have a default value in the "Link to Field" selection, which is then removed when another option is added.
The data is currently pulled in from another table using a 'Link to Field' column, I currently have the automation working to add default option back when options are removed but having difficulty creating the script to remove the default option when a second option is added.
Below is my current code, which pulls the current options from the cell and checks whether they are the same as the field being updated, which then passes those choices to an updateOptionsAsync, from which my understanding is the wrong function to be calling.
Any help would be greatly appreciated!!
let inputConfig = input.config(); let currentRecord =(inputConfig.recordID); let table = base.getTable("Deals"); let field = table.getField("Properties"); let queryResult =await table.selectRecordsAsync({fields:["Properties"]}); let results = queryResult.records;
//Get the recordID for the "New Product" Tag const tagsTable = base.getTable("Properties"); const tagRecords =await tagsTable.selectRecordsAsync({fields:['Property Address']}); let[newProductTagRecord]= tagRecords.records.filter( record =>(record.name ==="Default Property "));
//Logic for if the Tags Field is empty, in this case "null" if(myRecord?.getCellValue("Properties")==null){ await productsTable.updateRecordAsync(inputConfig.recordId,{ "Properties":[{id: newProductTagRecord?.id}] }) };
//Logic for if the Tags Field is 2 or more tags, then remove the "New Product" tag. if(myRecord.getCellValue("Properties").length >=2&& myRecord.getCellValue("Images (from Properties)").length >1){ let removeProductTagRecord = myRecord.getCellValue("Properties").filter( record =>(record.name !="Default Property ")); await productsTable.updateRecordAsync(inputConfig.recordId,{ "Properties": removeProductTagRecord }) };
I will say the documentation around this sort of stuff is very limited and from my POV, poorly documented where there is information, took a lot of googling and chatGPT to help me get to the final solution
//Get the recordID for the "New Product" Tag const tagsTable = base.getTable("Properties"); const tagRecords =await tagsTable.selectRecordsAsync({fields:['Property Address']}); let[newProductTagRecord]= tagRecords.records.filter( record =>(record.name ==="Default Property "));
//Logic for if the Tags Field is empty, in this case "null" if(myRecord?.getCellValue("Properties")==null){ await productsTable.updateRecordAsync(inputConfig.recordId,{ "Properties":[{id: newProductTagRecord?.id}] }) };
//Logic for if the Tags Field is 2 or more tags, then remove the "New Product" tag. if(myRecord.getCellValue("Properties").length >=2&& myRecord.getCellValue("Images (from Properties)").length >1){ let removeProductTagRecord = myRecord.getCellValue("Properties").filter( record =>(record.name !="Default Property ")); await productsTable.updateRecordAsync(inputConfig.recordId,{ "Properties": removeProductTagRecord }) };
I will say the documentation around this sort of stuff is very limited and from my POV, poorly documented where there is information, took a lot of googling and chatGPT to help me get to the final solution