Problem with gs.getUser().getRecord().getDisplayValue() when comparing in array

adriantan08
Giga Expert

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. 

1 ACCEPTED SOLUTION

Ankur Bawiskar
Tera Patron
Tera Patron

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

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

View solution in original post

6 REPLIES 6

vkachineni
Kilo Sage
Kilo Sage
Try gs.log(t.toString().indexOf(t1));
Please mark Correct and click the Thumb up if my answer helps you resolve your issue. Thanks!
Vinod Kumar Kachineni
Community Rising Star 2022

adriantan08
Giga Expert

ah, that's it. thanks for all the responses!