- 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 08:47 PM
Typecast the result with String type and see if you get result on using indexof:
var t = ["Finance", "Sales"];
var t1 = String(gs.getUser().getRecord().getDisplayValue('department'));
gs.log(t.indexOf(t1));
Hope this helps!
Cheers,
Manish
- 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
06-14-2023 11:19 PM
Hello @Ankur Bawiskar ,
I have written below to print the logged-in user's manager name. but I am not getting any value it's returning nothing. but for other reference filed like title, and location it's giving me proper data .please guide me.
thank you.
gs.print(gs.getUser().getRecord().getDisplayValue('manager'));
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-15-2023 12:44 AM
it worked fine for me in global scope. it won't work in scoped app
screenshot below
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader