importQuery.records filter help please

Hi All,

I’ve writing a script that uses an automation to create a list of tasks.
So what I have is an onboarding base with a table full of onboarding tasks, when a record in the employee onboarding table is added it need to create a list of task, based on there Job Title, so need to filter the list to only create the tasks that are relevant to the Job Title.

This is the script so far:

let inputConfig = input.config();
fname_var = ${inputConfig.FirstName};

sname_var = ${inputConfig.Surname};

sdate_var = ${inputConfig.StartDate};

sloc_var = ${inputConfig.StartLocation};

jtitle_var = ${inputConfig.JobTitle};

pemail_var = ${inputConfig.PersonalEmail};

lnman_var = ${inputConfig.LineManager};

let importTable = base.getTable(‘Onboarding checklist’);
let importView = importTable.getView(‘All onboarding tasks’);
let importQuery = await importTable.selectRecordsAsync();
let newTable = base.getTable(‘Employee OnBoarding’);

for (let record of importQuery.records) {
if(record.getCellValueAsString(‘Position’) == “Magento Back-End Developer”)
let field1 = record.getCellValue(‘Tasks’);
let {name: field2} = record.getCellValue(‘When?’);
let field3 = record.getCellValue(‘Notes’);
let field4 = record.getCellValue(‘Res’);

await newTable.createRecordsAsync([
    fields: {
    "First Name" : (fname_var),
    "Surname" : (sname_var),
    "Job Title" : (jtitle_var),
    "Start Date" : (sdate_var),
    "Start Location" : (sloc_var),
    "Personal Email" : (pemail_var),
    "Line Manager" : (lnman_var),
    "Tasks" : field1,
    "When?": field2,
    "Notes" : field3,
    "Resources" :  field4
    //"Due to Complete" : (due)


Just to add the script runs fine, but the if statement returns

This condition will always return ‘false’ since the types ‘readonly’

I’m probably going about this the wrong way so could do with a little help please.

Welcome to the community, @IT_Departmenrt! :smiley: Could you please share a screenshot of the actual error message that you’re seeing? What you typed looks like an incomplete message.

That aside, I have a couple of side comments.

First off, I don’t understand the purpose of the many output.set() lines in your script. The structure that you’re using—with an empty string as the first argument—is abnormal. If you actually want to pass data from the script to a later step, this isn’t going to work. If you’re not looking to pass data to later steps, then you can omit those output.set() lines entirely.

Also, you’re doing more than is necessary to take your input values and assign them to variables. There’s no need to use template literals to extract the values. For example, this:

fname_var = `${inputConfig.FirstName}`;

…could (and should) be more like this:

const fname_var = inputConfig.FirstName;

(Notice that I also added the missing const keyword before the variable name. You could use let if you prefer, but because you’re not modifying the value later, const is a more appropriate choice.)