client script or gliderecord script to get all the incidents whose company name is "eg."

subrat
Kilo Contributor

I want to know the client script or glidescript to get all the incident numbers those who are having same company name or a particular company name from incident table.

plz help me find the solution.

5 REPLIES 5

tony_barratt
ServiceNow Employee
ServiceNow Employee

Hi Subrat,


You can   dot walk to company.name


Along the lines of:


Screen Shot 2016-01-31 at 4.09.27 PM.JPG



Best Regards



Tony


Probably I should give an example of an encoded query used by a glide record query:



var queryString = "active=true^company.name=eg";


var gr = new GlideRecord('incident');



gr.addEncodedQuery(queryString);


gr.query();


while (gr.next()) {


    gs.log(gr.number);


}


output:


*** Script: INC0000055


Mike Allen
Mega Sage

To get a specific company:



var inc = new GlideRecord('incident');


inc.addQuery('company', '<sys_id of company>');


inc.query();


while(inc.next()){



gs.print(inc.number);



}



To look at all companies:


var inc = new GlideRecord('incident');


inc.orderBy('company');


inc.orderBy('number');


inc.query();


while(inc.next()){



gs.print(inc.company.name + ' - ' + inc.number);



}



This gets a count :


var inc = new GlideAggregate('incident');


inc.addAggregate('COUNT', 'company');


inc.query();


while(inc.next()){



var company = inc.company.name;


var companyCount = inc.getAggregate('COUNT', 'company');


gs.print(company + ' - ' + companyCount);



}



Any of these can be run in background scripts.


thanks mike,its very helpful.