indexOf or includes not working for System Properties having multiple comma separated values

Community Alums
Not applicable

Hi All, 

I'm facing strange issue in our platform that both indexOf() and includes() is giving unexpected output.Also I verified this works fine for single value,only issues are occuring when values are seperated by comma or like multiple values. Suspecting to break many codes. Need help.

Below script is giving '-1'/'false' as output.

var abc= '6a225461db861c50d4002db614961967';
gs.info(abc.includes(gs.getProperty('property_name')));

System Property:

find_real_file.png

1 ACCEPTED SOLUTION

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

you can use OOB ArrayUtil class to check using contains function instead of indexOf

var abc= '6a225461db861c50d4002db614961967';

var arr = gs.getProperty('property_name').toString().split(',');

var arrayUtil = new global.ArrayUtil();

var isPresent = arrayUtil.contains(arr,abc);

gs.info(isPresent);

ArrayUtil - Global

Regards
Ankur

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

View solution in original post

7 REPLIES 7

We can easily overlook certain things, right!

Happened with me several times 😉

Best Regards
Aman Kumar

Community Alums
Not applicable

Thanks Aman for the RCA.

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

you can use OOB ArrayUtil class to check using contains function instead of indexOf

var abc= '6a225461db861c50d4002db614961967';

var arr = gs.getProperty('property_name').toString().split(',');

var arrayUtil = new global.ArrayUtil();

var isPresent = arrayUtil.contains(arr,abc);

gs.info(isPresent);

ArrayUtil - Global

Regards
Ankur

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