- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-05-2019 08:29 PM
Hi, Guys.
I stumbled upon this interesting observation.
So when I did this:
var t = ["Finance", "Sales"];
var t1 = gs.getUser().getRecord().getDisplayValue('department');
gs.log(t.indexOf(t1));
this will always evaluate to -1. It's very odd because doing a simple == comparison returns true (i.e. t1 == "Finance").
Please let me know if there's just something I'm missing - could even be a something I'm missing in basic javascript.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-05-2019 09:00 PM
Hi Adrian,
are you trying to search the department value into that array then do this;
indexOf doesn't work properly on array in servicenow; instead use ArrayUtil ServiceNow class
var t = ["Finance","Sales"];
var t1 = gs.getUser().getRecord().getDisplayValue('department');
var arrUtil = new ArrayUtil();
var val = arrUtil.indexOf(t, t1);
gs.info(val);
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
08-05-2019 09:23 PM
Vinod Kumar Kachineni
Community Rising Star 2022
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-06-2019 12:23 AM
ah, that's it. thanks for all the responses!