Help

Re: importQuery.records filter help please

2147 0
cancel
Showing results for 
Search instead for 
Did you mean: 
IT_Departmenrt
5 - Automation Enthusiast
5 - Automation Enthusiast

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();
output.set(’’,${inputConfig.FirstName});
fname_var = ${inputConfig.FirstName};

output.set(’’,${inputConfig.Surname});
sname_var = ${inputConfig.Surname};

output.set(’’,${inputConfig.StartDate});
sdate_var = ${inputConfig.StartDate};

output.set(’’,${inputConfig.StartLocation});
sloc_var = ${inputConfig.StartLocation};

output.set(’’,${inputConfig.JobTitle});
jtitle_var = ${inputConfig.JobTitle};

output.set(’’,${inputConfig.PersonalEmail});
pemail_var = ${inputConfig.PersonalEmail};

output.set(’’,${inputConfig.LineManager});
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)
    },
}])
}

}

2 Replies 2
IT_Departmenrt
5 - Automation Enthusiast
5 - Automation Enthusiast

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! :grinning_face_with_big_eyes: 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.)