Oct 08, 2021 07:14 AM
I’m looping over some records and want to increment ‘i’ ONLY if both conditions below are met:
let i = 0;
for (let record of taskRecords.records) {
if(id.includes(record.getCellValue('ID Lookup')) && record.getCellValue('Stage').includes(stage)) {
i++;
}
}
console.log(i);
My problem is the second condition. The cell value of the field ‘Stage’ is “This is just some dummy text | this is a string” and it’s searching for “this is a string” (this is called ‘stage’ and is a string from a previous step in an automation).
i remains 0 in this case. Can anyone explain why includes doesn’t work on the second condition? Thanks!
Solved! Go to Solution.
Oct 08, 2021 08:58 AM
What type of field is your ‘Stage’ field?
Depending on the field type it may need to be coerced into a string. Maybe try using the method getCellValueAsString instead of getCellValue?
Oct 08, 2021 08:58 AM
What type of field is your ‘Stage’ field?
Depending on the field type it may need to be coerced into a string. Maybe try using the method getCellValueAsString instead of getCellValue?
Oct 08, 2021 09:10 AM
Hi,
just guessing - string method ‘includes’ is case-sensitive, if your “this is a string” in cell starting from capital, try to search for “his a string”
Oct 08, 2021 10:16 AM
Here’s a generic troubleshooting tip.
Assign the cell values to variables. Then console.log all the variables before your `if`` statement. One or more of the values may not be what you expect.
Oct 08, 2021 01:09 PM
On top of that, if you’re polling non-array stuff with Array.prototype.includes, you’re going to have a bad time, that syntax only works due to destructuring coercion shenanigans which really aren’t the type of behavior you want your code to depend on. Look into substring/substr methods if the cell value is a string.
Oct 08, 2021 01:56 PM
Both strings and arrays have an includes()
method. So, if you don’t know what data type you have (array versus string), you might get expected results for the wrong reasons.
Oct 09, 2021 08:19 AM
This was it. I was running .includes on an object and not a string. So that worked, thank you!
Oct 09, 2021 08:21 AM
As @kuovonne mentioned, .includes exists for strings as well. For my understanding (JS noob here): where do you see the issue with that? Thanks