This is going to be a 2 part question. Overall goal is to write a script that will add the selected values of a multi-select field on a transaction record to an array, use If statements to look for a string in the array and when found call an email function to email a specific recipient. I'm having issues with the string lookup and calling the email function and continuing the iteration through the array.
Part 1) How to lookup a specific string in an array? What I have below uses the concept of if (array == "String") { do something. The issue here is if there is more than one value in the array, the if statement is satisfied and the loop seems to exit.
/** * Global Variable Declaration */ var recipient = ""; var cc = []; var practices = []; practices.push(nlapiGetFieldTexts('custbody50')); ... function cs_RequestSOW(){ console.log("Request SOW Button Pressed"); nlapiSetFieldValue('custbody_sow_rqstd', 'T'); nlapiSetFieldValue('custbody_sow_req_date', date); for (var i = 1; i <= practices.length; i++){ alert(practices); if (practices == "Big Data"){ alert("The Practice is " + practice); recipient = "bigdataemail@mycompanysdomain.com"; console.log(recipient); cs_emailPractice(); }else if (practices == 'Cloud & Automation' || practices == 'Dev Ops'){ alert("The Practice is " + practices); recipient = "cloudautodevopsemail@mycompanysdomain.com"; console.log(recipient); cs_emailPractice(); }else if (practices == 'Compute'){ alert("The Practice is " + practices); recipient = "computeemail@mycompanysdomain.com"; console.log(recipient); cs_emailPractice();Part 2) How to call the cs_emailPractice() function when a string is found in the array but also continue the loop looking for other matches? The cs_emailPractice() function is located further down in the script record so I don't need to call a different script in my execution.