Help

Updating Multi-select fields in a loop

Topic Labels: Scripting extentions
964 1
cancel
Showing results for 
Search instead for 
Did you mean: 
Paul_Lee1
4 - Data Explorer
4 - Data Explorer

Hi all,

I have been stuck on this for awhile now, would appreciate any help! I’ll try my best to explain:

I am trying to create an automated tagging solution to read through a text field and tag it in a multi-select based on specific keywords.

Screen Shot 2022-09-01 at 8.29.17 AM

Where I am running into trouble is after I push items into the array, those items stay in the array and each record thereafter will retain the tags from the previous record even if they do not apply to the specific record. I am also stumped on how to batch the loop. Here is what I have so far:

let table = base.getTable('Intakes/Submissions');
const feedbacktype = table.getField('Feedback Tag');
const existingtags = vocchoices.options.choices;
const feedbacktags = feedbacktype.options.choices;
let query = await table.selectRecordsAsync({fields: table.fields});

let aTags = [];

for (let record of query.records){

    let choices = record.getCellValue("[U] User Product Feedback");
    let options = record.getCellValue("Feedback Tag");
    let feedbackcat = record.getCellValue("Feedback Category");     

    if(feedbackcat != null && options != null && feedbackcat.name === "Product Suggestions"){
        let parent = options.map(test => test.name).toString();
        if(parent.includes("Creating a show") || parent.includes("Hosting a show")){
            aTags.push("Creator Studio");
        }
        if(choices.includes("playlist")){
            aTags.push("Playlist");
        }    
    }
   await table.updateRecordAsync(...)
}

Is there a way to empty the array after each iteration? Or am I just thinking this through wrong?

1 Reply 1

Yup: move this line inside the loop, somewhere at the beginning of the loop before things are pushed into it:

let aTags = [];