HI - I am trying to create a conditions that I thought would be fairly simple. Well apparently not for me. I have a detail table and simply want the condition to look at a field and if it includes part of a word then return the text ‘Partner’ otherwise return ‘Other’. I have the below condition and it doesnt seem to be reading all the records in the detail table. My result is ‘BPAS’ for all the records.
results.each(function(index) {
if (record.tables[“CU_vendor”][index].fields[“pay_to_name”].includes(“BPA”)){
results.text(“BPA”);}
else {
results.text("Partner")}
});
What did I do wrong?
Thank You
You should call this.text instead of results.text (in both places). With results.text you’re modifying all matched elements instead of just the current iteration (this).
1 Like
Thank you - that worked!!
Hi @ahaddad, I see that the provided JavaScript code contains a minor visual issue, which isn’t a problem on its own, but for others searching for a similar solution I would like to share the following:
The indicated issue can be resolved by applying the following JavaScript code instead:
// (1) Replaced 'results' for 'this'
results.each(function (index) {
if (record.tables["CU_vendor"][index].fields["pay_to_name"].includes("BPA")) {
this.text("BPA"); // (1)
} else {
this.text("Partner"); // (1)
}
});
1 Like