- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-23-2022 11:15 PM
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:
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-23-2022 11:27 PM
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);
Regards
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
05-23-2022 11:18 PM
Can you try
var abc= '6a225461db861c50d4002db614961967';
gs.info(abc.indexOf(gs.getProperty('property_name'))>-1);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-23-2022 11:21 PM
Thanks for quick response.Still false only 😞

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-23-2022 11:20 PM
Hey you should be doing:
var prop = gs.getProperty("prop_name");
var sysID = 'your_keyword';
gs.info(prop.indexOf(sysID));
I think you are doing it other way around
Feel free to mark correct, If I answered your query.
Will be helpful for future visitors looking for similar questions 🙂
Aman Kumar

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-23-2022 11:22 PM
Nice catch.