Save the date! Join us on October 16 for our Product Ops launch event. Register here.
Sep 09, 2021 10:45 AM
I need to know how i ask to run script when new record is created and define if name
in:
var response = await fetch('https://api.agify.io/?name='+name);
is equal to Prénom
used from table else only change records only for this person.
I give you a screen of my table
// query for every record in "trombinoscope"
let table = base.getTable("test");
let view = table.getView("Donnée brut");
let query = await view.selectRecordsAsync
(
{
sorts:
[
// sort by "Prénom" in ascending order...
{field: "Prénom"},
]
}
);
let records = query.records;
// print ID & "Prénom" from each record:
for (let record of query.records)
{
let name = (record.getCellValueAsString('Prénom')) ;
let response = await fetch('https://api.agify.io/?name='+name);
/*fetch('https://api.agify.io/?name='+name) ;*/
/*console.log((await response.json()).age);*/
let agifyAge = (( await response.json()).age);
let records = query.records;
for (let i=0 ; i<records.length ; i++ )
{
/*if ( name == ((await response.json()).name) )*/
await table.updateRecordsAsync(
[
{
id: records[i].id ,
fields :
{
"Age estimé" : agifyAge ,
},
},
]);
}
/*console.log(await response.json());*/
/*let json = JSON.parse(await response.json());
console.log(json["age"]);*/
}
Sep 09, 2021 02:51 PM
Create an automation that triggers when a record is created or when a record enters a view. I prefer the latter for better assurance that all the fields in the record are complete.
From this action, add a script action to capture the Prénom
field value into variables from the previous step using the output feature.
// get the `Prénom` field value from the previous step
let inputConfig = input.config();
let thisPrénom = inputConfig.Prénom;
You are now ready to perform the fetch() call and test to see if it matches the captured thisPrénom
value.
Sep 09, 2021 03:29 PM
So i’m had to put
let inputConfig = input.config(); let thisPrénom = inputConfig.Prénom;
in my for (let record of query.records)
just before my fetch that right.
I’m sorry to ask this basic question but i’m learn my first time js :grinning_face_with_sweat: .
Sep 10, 2021 07:35 AM
No - your requirement is simpler:
Done