Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Need Help on how to use IndexOf in below query.

Alok21
Giga Expert

Hi Team,

Need your assistance on below query.

I am trying to set a condition for notification to get triggered. I am now got stuck on how to use indexOf in below gliderecord query. So what i am trying to compare is, When the catalog is "Technical Catalog", notification should not be sent. Below is the script i have and it is triggering even for "Technical Catalog" which it should not.

Can anyone please help on this, what am i doing wrong?

answer = true;
var gr = new GlideRecord("sc_req_item");
gr.addQuery("request", current.sys_id);
gr.query();
if (gr.next()) {
if (gr.cat_item.sc_catalogs == indexOf(gs.getProperty("tc.item.catalogs.type")));
answer = false;
}

Regards,

Alok kumar sahu

1 ACCEPTED SOLUTION

Ashutosh Munot1
Kilo Patron
Kilo Patron

HI,

If the value exist then it will return its position and if it does not then it will return -1.


So we have to compare that as well. Use below code:

 

if(gr.cat_item.sc_catalogs.indexOf(gs.getProperty("tc.item.catalogs.type")) >-1)

//THis means if the value in gr.cat_item.sc_catalogs is present in ur property then it will enter if loop.


Thanks,
Ashutosh

View solution in original post

5 REPLIES 5

VigneshMC
Mega Sage

Try

 if (gr.cat_item.sc_catalogs.indexOf(gs.getProperty("tc.item.catalogs.type"))!=-1);

Ashutosh Munot1
Kilo Patron
Kilo Patron

HI,

If the value exist then it will return its position and if it does not then it will return -1.


So we have to compare that as well. Use below code:

 

if(gr.cat_item.sc_catalogs.indexOf(gs.getProperty("tc.item.catalogs.type")) >-1)

//THis means if the value in gr.cat_item.sc_catalogs is present in ur property then it will enter if loop.


Thanks,
Ashutosh

Thank you Ashutosh 🙂

You are welcome bro.