You haven't shown what the inputs or the outputs to the script are, so it is hard to tell what is going on. For example, are you getting any output in the console?
My guess from reading the script is that your script does not output anything to the console, because input.record is undefined and thus nothing in your if statements ever executes.
Can you share more about your coding experience and what resources you used to write this script?
Hi,
if you really want to
// Check if input.record is defined
put
console.log(input.record) somewhere - you'll see it is undefined
in order to get record, you need to query it
you can add record ID to the input parameters
then
const {teamsNeeded,ID}=input.config()
let record=await base.getTable('YOUR_TABLE_NAME').selectRecordAsync(ID)
then continue your script, put 'record' instead of 'input.record. in loop
if linter annoys you that 'record could be null', you can use:
if (record && record.getCellValue('Field') - exactly what you did
if (record?.getCellValue('Field')) - this is shorter form of higher
if(!record) throw new Error ('Record not defined') - put it somewhere before the if(record clause, maybe even outside the loop, but i'm not sure, testing needed. So-called 'guard clause' describes 'pessimistic' scenario at first, then work with others. Usually it helps to avoid complex nested IFs.
I would recommend to do it and test and then check about ES6 way
this part
let allLeadsAssigned = true;
for (const team of teamsNeeded) {
const leadField = teamLeadFields[team];
// Check if input.record is defined
if (input.record && !input.record.getCellValue(leadField)) {
console.log(`Lead field '${leadField}' is empty for team '${team}'`); // Add this line
allLeadsAssigned = false;
break; // No need to check further
} else if (input.record) {
console.log(`Lead field '${leadField}' is filled for team '${team}'`); // Add this line
}
}
if you OK with the fact that console.log('Lead field '${leadField}' is empty/filled ') can be omitted,
all this block can be substituted by
let allLeadsAssigned = teamsNeeded.every(team => record.getCellValue(teamLeadFields[team]))
I suggest to not use 'short' way until you check 'long' and sure to understand how 'short' works
And by the way, if your multiselect options doesn't include each other (like, for example. 'inactive' includes ' active'), you can do all this by a formula, without script. That's the first real world scenario I've seen here to use XOR logical function.
You haven't shown what the inputs or the outputs to the script are, so it is hard to tell what is going on. For example, are you getting any output in the console?
My guess from reading the script is that your script does not output anything to the console, because input.record is undefined and thus nothing in your if statements ever executes.
Can you share more about your coding experience and what resources you used to write this script?
Apologies - I did not specify in my original post that I did have an input for teamsNeeded so the output in the console was including the teams needed as expected. I was able to resolve this issue with @Alexey_Gusev solution below. Thank you!
Hi,
if you really want to
// Check if input.record is defined
put
console.log(input.record) somewhere - you'll see it is undefined
in order to get record, you need to query it
you can add record ID to the input parameters
then
const {teamsNeeded,ID}=input.config()
let record=await base.getTable('YOUR_TABLE_NAME').selectRecordAsync(ID)
then continue your script, put 'record' instead of 'input.record. in loop
if linter annoys you that 'record could be null', you can use:
if (record && record.getCellValue('Field') - exactly what you did
if (record?.getCellValue('Field')) - this is shorter form of higher
if(!record) throw new Error ('Record not defined') - put it somewhere before the if(record clause, maybe even outside the loop, but i'm not sure, testing needed. So-called 'guard clause' describes 'pessimistic' scenario at first, then work with others. Usually it helps to avoid complex nested IFs.
I would recommend to do it and test and then check about ES6 way
this part
let allLeadsAssigned = true;
for (const team of teamsNeeded) {
const leadField = teamLeadFields[team];
// Check if input.record is defined
if (input.record && !input.record.getCellValue(leadField)) {
console.log(`Lead field '${leadField}' is empty for team '${team}'`); // Add this line
allLeadsAssigned = false;
break; // No need to check further
} else if (input.record) {
console.log(`Lead field '${leadField}' is filled for team '${team}'`); // Add this line
}
}
if you OK with the fact that console.log('Lead field '${leadField}' is empty/filled ') can be omitted,
all this block can be substituted by
let allLeadsAssigned = teamsNeeded.every(team => record.getCellValue(teamLeadFields[team]))
I suggest to not use 'short' way until you check 'long' and sure to understand how 'short' works
And by the way, if your multiselect options doesn't include each other (like, for example. 'inactive' includes ' active'), you can do all this by a formula, without script. That's the first real world scenario I've seen here to use XOR logical function.
Thank you @Alexey_Gusev! Adding ID as an input and adjusting to the 'short' way for allLeadsAssigned worked.