Help

Re: Updating multiple records with results of Find Records

971 0
cancel
Showing results for 
Search instead for 
Did you mean: 
wooti
6 - Interface Innovator
6 - Interface Innovator

As in the title, I’m trying to update multiple records with the results of a Find Records step.

I’ve got my ‘When a record is updated’ Trigger and ‘Find Records’ Action step set up correctly, but I’m having trouble with the script Action that comes afterwards.

I’ve adapted the code of another forum user (which updated a single-select field when records matched Find conditions):

let jobsTable = base.getTable("Jobs")
let packagelinkFieldName = "Package Link"

let inputConfig = input.config()
let recordsToUpdate = inputConfig.recordId
let thepackagelink = inputConfig.packageLink

let updates = new Array

for (let record of recordsToUpdate){
    updates.push({
        id: record,
        fields:{
            [packagelinkFieldName]: {name: thepackagelink}
        }
    })
}

while (updates.length > 0) {
    await jobsTable.updateRecordsAsync(updates.slice(0, 50));
    updates = updates.slice(50);
}

The error I’m getting is:
Error: Field “fldZN1J0lfQqAQwXo” cannot accept the provided value.
at main on line 20

The Package Link field is a URL. I want the data in the ‘Package Link’ field to be inserted into the Package Link field for all records that match the Find Record action.

My input variables are:
recordId (which is the list of record IDs from the Find step)
packagelink (which is the input from the Trigger “when Package Link is updated”)

I’ve confirmed through an F12 inspect that the field ID above is for the Package Link field.

Where am I going wrong?

1 Reply 1

Hi,

The task is quite harder
you have arrays of input data, and when you iterate through recordToUpdate, you are trying to put whole array thepackagelink into each field, which refuses to get it. Instead, you need to add iteration of thepackagelink.
You don’t need to create inner loop.
Imagine your recordsToUpdate is [111,222,333,444,555], I omitted string quotes to simplify.
Your package link variable is something like [linka,linkb,linkc,linkd,linke] , so you need to put index, which iterates from 0 to 4 (in this case)

i’m usually not using ‘for’ loops. so I can’t tell what is ‘best practice’, but there’s one option:


let count=0
let updates = new Array

for (let record of recordsToUpdate){
    updates.push({
        id: record,
        fields:{
            [packagelinkFieldName]: {name: thepackagelink[count]}
        }
    })
count++
}

I just solved a similar puzzle so I even can show a demo
that’s why your field refused to get value:

image

Another way, to avoid “spawning unnecessary entities” (I don’t know correct English sentence for that), index may follow array size, which increases together with loop counter.

image

I hope, you will do the rest :slightly_smiling_face: