- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-23-2019 06:47 AM
I having trouble with an array. I'm trying to find if any of the choices that were selected is a Tier 3 group type. If so, then stop processing and make tier3 = true. So I hard coded the array and tested it on the BackGround Script:
var tor = "BigPipe,Cell Base,Cloud Connectivity";
var tor_array = tor.split(',');
var i;
var grouptype;
var tier3;
var endLoop;
var gr = new GlideRecord('u_onenet_type_of_request');
gr.addQuery('u_active', true);
gr.query();
while(gr.next()){
for (i=0; i < tor_array.length; i++) {
gs.log("LAK length " + tor_array.length);
if (gr.u_type_of_request == tor_array[i]){
grouptype = gr.u_onenet_group_type;
gs.log("LAK Type of Request " + gr.u_type_of_request);
gs.log("LAK Grouptype " + grouptype);
if(grouptype == 'Tier 3'){
tier3 = true;
} else {
tier3 = false;
}
}
if (tier3 == true){
endLoop = true;
break;
}
}
if (endLoop == true){
break;
}
}
This works like a charm, but when I change the tor variable to: "BigPipe, Cell Base, Cloud Connectivity"; (with spaces) I only get info back from the BigPipe variable.
Problem is when I actually script out var tor_array = current.variables.ref_type_of_request.getDisplayValue().split(','); and I look to see what's in there, it's "BigPipe, Cell Base, Cloud Connectivity";
Are the spaces making a difference? Or is it something else?
Lisa
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-23-2019 07:11 AM
Hi Kemmy,
yes spaces would make a difference.
A string with "hello" and "hello " has a difference and the query won't run properly.
better trim the leading and trailing spaces using trim() method
if (gr.u_type_of_request == tor_array[i].trim()){
Mark Correct if this solves your issue and also mark Helpful if you find my response worthy based on the impact.
Thanks
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-23-2019 07:11 AM
Hi Kemmy,
yes spaces would make a difference.
A string with "hello" and "hello " has a difference and the query won't run properly.
better trim the leading and trailing spaces using trim() method
if (gr.u_type_of_request == tor_array[i].trim()){
Mark Correct if this solves your issue and also mark Helpful if you find my response worthy based on the impact.
Thanks
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-23-2019 07:23 AM
THANK YOU!!! This worked like a charm!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-23-2019 07:32 AM
Hi Kemmy,
Can you also mark my answer as helpful? Thanks in advance.
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader