Glide Record Notification

akunk23
Kilo Contributor

I'm very new to using GlideRecord. I'm writing an advanced condition to specify when to send an email notification. Right now my script is working for the "Field" notification(I'm not wanting to send the notification then). But now I need to add another statement to check if the sc_req_item is "IT"(and also not send the notification)... How would I add an OR statement to my script to include "IT". Thanks in advance

var gr= new GlideRecord("sc_req_item");

gr.addQuery("cat_item.name","Field");

gr.addQuery("request",current.getValue("sys_id"));

gr.query();

if(gr.next()){

answer=false;

}

else{

answer=true;

}

1 ACCEPTED SOLUTION

Robbie
Kilo Patron
Kilo Patron

Hi akunk23,



See this link, this will provide you with what you're after:


http://wiki.servicenow.com/index.php?title=GlideRecord#addOrCondition



It should look something like below if 'IT' is the name of the item.




var gr= new GlideRecord("sc_req_item");


var qc = gr.addQuery("cat_item.name","Field");


qc.addOrCondition('cat_item.name', 'IT');


gr.addQuery("request",current.getValue("sys_id"));


gr.query();


if(gr.next()){



answer=false;


}


else{


answer=true;


}



For future GlideRecord querying, also see these links.


Also see 'Encoded Queries' and how to generate an encoded queries:


http://wiki.servicenow.com/index.php?title=GlideRecord#addEncodedQuery


Encoded Query Strings - ServiceNow Wiki




Thanks,


Robbie



Please mark correct and helpful by clicking on your post link (Glide Record Notification ) to help others with the same/similar question.


View solution in original post

8 REPLIES 8

Robbie
Kilo Patron
Kilo Patron

Hi akunk23,



See this link, this will provide you with what you're after:


http://wiki.servicenow.com/index.php?title=GlideRecord#addOrCondition



It should look something like below if 'IT' is the name of the item.




var gr= new GlideRecord("sc_req_item");


var qc = gr.addQuery("cat_item.name","Field");


qc.addOrCondition('cat_item.name', 'IT');


gr.addQuery("request",current.getValue("sys_id"));


gr.query();


if(gr.next()){



answer=false;


}


else{


answer=true;


}



For future GlideRecord querying, also see these links.


Also see 'Encoded Queries' and how to generate an encoded queries:


http://wiki.servicenow.com/index.php?title=GlideRecord#addEncodedQuery


Encoded Query Strings - ServiceNow Wiki




Thanks,


Robbie



Please mark correct and helpful by clicking on your post link (Glide Record Notification ) to help others with the same/similar question.


Alikutty A
Tera Sage

Hi,



You can try this code



var gr= new GlideRecord("sc_req_item");


gr.addQuery("cat_item.name","Field");


gr.addOrCondition("cat_item.name","IT");


gr.addQuery("request",current.getValue("sys_id"));


gr.query();


if(gr.next()){



answer=false;


}


else{


answer=true;


}





Thanks


PS: Hit like, Helpful or Correct depending on the impact of the response


Another simplified way is to use an addEncodedQuery() instead of addQuery()



var gr= new GlideRecord("sc_req_item");


gr.addEncodedQuery("cat_item.name=Field^ORcat_item.name=IT^request="+current.getValue("sys_id"));


gr.query();


if(gr.next()){


  answer=false;


}else{


  answer=true;


}




Thanks


PS: Hit like, Helpful or Correct depending on the impact of the response


Laurie Marlowe1
Kilo Sage

Hi akunk23,



You can add an or condition easily:   http://wiki.servicenow.com/index.php?title=GlideRecord#gsc.tab=0



GlideRecord - ServiceNow Wiki



Thanks,



Laurie