Help

Script to update several fields in multiples records

Topic Labels: Automations
2148 5
cancel
Showing results for 
Search instead for 
Did you mean: 
JULIANA_MONTES
4 - Data Explorer
4 - Data Explorer

Hi, I am trying to update several fields in multiple records, but I have an error when I tried to use the input variables from previous automation actions. The fields that I tried to update are “Invoice” and “Invoice Status” which are single select and “Date invoice” is a date.

Here is my script and screenshot:

let inputConfig = input.config(); //
let records = inputConfig.step2Records
let dateI = inputConfig.dateInvoices
let table = base.getTable("Payouts"); // 
for (let record of records) {
    await table.updateRecordAsync(record, {
    "Invoice": {name: inputConfig.invoicesID}, "Date Invoice": dateI, "Invoice Status":{name:"Completed"} //Replace Emailed with the field name of the checkbox field you want to update, if different.
    })
}

Error

Thanks for any help!

5 Replies 5

That’s pretty weird, it looks like you’ve got everything set up properly

I can take a look at it for you if you’d like, just DM me an invite link

In the meantime, could you try refreshing the data that the automation is using perhaps? i.e. choosing the record again from the trigger action? Apologies if you’ve already done this; personally I forget this a lot and more often than not find that it’s the old data that’s the cause of my problems

Thanks for your reply. Yes, it is very strange, I have already refreshed all the data and the trigger and it still doesnt work. The only difference I see between the variable input “Step2record” which works fine is that the information comes from a Find records action step. On the other hand the other two inputs that it does not recognize and underlines in red come from the trigger “When a form is submitted”. Do you think these have an impact?

The other strange thing is that although they tell me that this property does not exist and underline it in red, when I run them in the console.log, it correctly brings me all the data of the three variables.

The other thing that may be affecting is the format with which I am adding the variables to the record I understand that to add single select fields is like this: “Invoice”: {name: inputConfig[“invoicesID”]}. The one I don’t know how to add is when it is a date field, at this moment I am adding it like this “Date Invoice”: dateI. Do you think Im adding the variables in the correct way?

I sent you this new screenshot with the console.log and commented what other attempts I have made in the code.
image

Regarding the link, sorry I have never shared a link here, and I have the doubt, if I share the link to my base, I will be charged the 20USD per month for your user in airtable or just charge me only those days? Additionally, do you need a read only or publisher link?

Hmm, I don’t think so. As long as a date value exists when the form is submitted, that should work fine

I…think so? I attempted to recreate this myself by passing in a value from a Date field and then used a script to update another Date field with that value with the same code as yours, and it worked fine:

await table.updateRecordAsync(record, {
  "Date 2": variableDate
})

Screenshot 2022-08-11 at 10.03.08 AM
Screenshot 2022-08-11 at 10.03.00 AM

Ah sorry, thank you for bringing that up. Could you do the following to avoid the charge?

  1. Duplicate the base
  2. Move the new base into a free workspace
  3. Invite me to the new base

I’ll still be able to see your scripts and automations so I can help you troubleshoot it, I just won’t be able to run them

Creator access please!

Hi,
just a guess - maybe you are trying to set single-select value, which is not available in current field options?
Check which field produces error
image

using that one-liner:
output.table(Object.fromEntries([...base.getTable(cursor.activeTableId||'').fields.map(x=>([x.name,{type:x.type,id:x.id}]))]))
or ‘Manage fields’ if you has it on your plan

automation script interface linter is a bit bugged, when you change input variables and sometimes behave like old settings are still active.

if i’m right and the problem is ‘Invoice’ field, which has no ‘2208-31’ option, before setting this value, you should add it to the list of available choises, like in API docs example

image

Also, instead of

you can write
let {step2Records, dateInvoices}=input.config()

and then use these variables in code (or {records,dateI} if you want, you should just repeat the same names that you defined in ‘input variables’ part)