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

Jaspal Singh
Mega Patron
Mega Patron

Can you try

var abc= '6a225461db861c50d4002db614961967';
gs.info(abc.indexOf(gs.getProperty('property_name'))>-1); 

Community Alums
Not applicable

Thanks for quick response.Still false only 😞

Aman Kumar S
Kilo Patron

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 🙂

Best Regards
Aman Kumar

Nice catch.