Help

Scripting Error

Topic Labels: Automations
2668 5
cancel
Showing results for 
Search instead for 
Did you mean: 
Eitan
5 - Automation Enthusiast
5 - Automation Enthusiast

Hello!

I have practically no experience with Javascript and scripting but I am turning to the Run Script in my Airtable automation as a last resort.

In my automation I am finding a list of schools and then using a repeating group to go through each school and find values where the school is in the schedule table. I am running a script in this repeating loop to get all the entries in the schedule where the input value is from the schools. I am doing this so I can then order these according to start date which Airtable doesn't let me do.

You can see my automation in the attached screenshot.

The script is below and it works but I keep get an error on schoolName (which you can see in my other attached screenshot) telling me:

 

Property 'schoolName' does not exist on type '{}'.(2339)

 

Can anyone help? I don't really know why I am getting this error?

 

 

 Thank you!

let school = input.config();

console.log(`The value of schoolName is ${school.schoolName}`);

// query for all the records in a table
let table = base.getTable(" Schedule");
let tableView = table.getView("Prep Emails Automation")
let queryResult = await tableView.selectRecordsAsync({
    fields: ["Name", "Term", "School"],
    sorts: [
       // sort by "Start Date" in ascending order
       {field: "Start Date"},
    ]
});

// print ID & "Name" from each record:
for (let record of queryResult.records.filter(record => (record.getCellValueAsString("School") == `${school.schoolName}`))) {
    console.log(`
**${record.id}**
${record.getCellValueAsString("Name")}
`);
}

 

5 Replies 5

Sometimes the script editor has trouble parsing input variables.

Have you tried running the script anyway?

Have you tried closing the script editor and reopening it?

Are you sure that the field has a value for the triggering record?

Dan_Montoya
Community Manager
Community Manager

Try changing the line to this:

console.log(`The value of schoolName`,  $school);

Then you can expand $school in the console to see what values are there.

A closer look at the screen shot shows that the schooName input variable is being set. The output on the right panel shows that the value is Astra College. It's just the linter in the script editor that is getting confused.

kuovonne_0-1707931387388.png

By the way, it looks like your script currently does not change any record data and does not output any data for future automation steps. Do you have plans on how to change the record data? Are you personally interested in learning scripting, or do you just want a working solution?

Eitan
5 - Automation Enthusiast
5 - Automation Enthusiast

Thank you both for your response! yep so I have closed Airtable and this morning on re opening everything is working fine without any error -- a bit odd but I'll go with it

It was working yesterday but the error made me think while it was working there was still a problem with the code which needed to be fixed.

and yes! I am very interested in learning scripting/coding, so keen to let this opportunity be one that I can learn from. It doesn't transform the data, I don't actually need it to do that -- all I want it to do is to select the records and sort them chronologically according to their start date.

What I am curious about now is how to output those entries as an array or some kind of table that I can then send in an email in a future step...? if that makes sense

 

 

Eitan
5 - Automation Enthusiast
5 - Automation Enthusiast

Ok now I can get it to work and output an array of the found records. Later in the automation I want it to send an email with those records, however, it only works for the first one that was used as test data in the script? the repeating group doesn't appear to be iterating through the list that was selected earlier in a find records 

So the first email with 'Astra College' shows their records but then the next emails show blank records...

do I need to somehow clear the script so that it gets the next variable for input.config()? or something like that?

let school = input.config();

console.log(`The value of schoolName is ${school.schoolName}`);

// query for all the records in a table
let table = base.getTable("📅 Schedule");
let tableView = table.getView("Prep Emails Automation")
let queryResult = await tableView.selectRecordsAsync({
    fields: ["Name", "Term", "School", "Start Date"],
    sorts: [
       // sort by "Start Date" in ascending order
       {field: "Start Date"},
    ]
});

let upcomingSchedule = [];

let filteredResults = queryResult.records.filter(record => (record.getCellValueAsString("School") == `${school.schoolName}`));

// print ID & "Name" from each record:
for (let record of filteredResults) {
    console.log(`**${record.id}**
${record.getCellValueAsString("Name")}`);
    
    upcomingSchedule.push ({
        fields: {
            "Date": `${record.getCellValueAsString("Start Date")}`,
            "Name": `${record.getCellValueAsString("Name")}`,
        }
    })

}

output.set(`${school.schoolName}`, upcomingSchedule);