Retrieving sys_id

Martin45
Tera Contributor

Hi team,

I have the list of business rules on DEV and PROD with incident and task table. PROD environment has 7 more business rules and I need to find out which of them are missing in DEV. To be 100% sure I would like to compare with sys_id.

Could you please advise how I could retrieve sys_id for every single business rule on the list so I can compare them in excel then?

 

Thank you,

Martin

2 ACCEPTED SOLUTIONS

Saurabh Gupta
Kilo Patron
Kilo Patron

Hi,
Create a new record as below-
https://your_instance.service-now.com/sys_ui_list.do?sys_id=6176a532d700310066f70eca5e61039f

SaurabhGupta_1-1704890703234.png

 



Result:

SaurabhGupta_0-1704890621493.png

 


Thanks and Regards,

Saurabh Gupta

View solution in original post

Amit Verma
Kilo Patron
Kilo Patron

Hi @Martin45 

 

If you want to fetch the Business Rule via script, you can use below logic :

 

var Headers = ["Name","Table","Description"];
var fileName = 'BusinessRules.csv';
var csvData = '';
for (var i = 0; i < Headers.length; i++) { 
	csvData = csvData + '"' + Headers[i] + '"' + ',';
}
csvData = csvData+"\r\n";
var gr = new GlideRecord('sys_script');
gr.addActiveQuery();
gr.query();
while(gr.next()){
csvData = csvData + '"' + gr.name + '",' + '"' + gr.collection+ '",' + '"' + gr.description+'"';
csvData = csvData+"\r\n";
}
var grRec = new GlideRecord("incident");
grRec.addQuery("sys_id","sys_id of a test incident record");
grRec.query();
if(grRec.next()){
var grAttachment = new GlideSysAttachment();
grAttachment.write(grRec,fileName, 'application/csv',csvData);
}

 

This will generate a csv file on the test incident provided as an input and you can download that to proceed. Also, if you want more columns to be added, that could be done by tweaking the csv headers and the data fetch logic.

 

Thanks & Regards

Amit Verma


Please mark this response as correct and helpful if it assisted you with your question.

View solution in original post

2 REPLIES 2

Saurabh Gupta
Kilo Patron
Kilo Patron

Hi,
Create a new record as below-
https://your_instance.service-now.com/sys_ui_list.do?sys_id=6176a532d700310066f70eca5e61039f

SaurabhGupta_1-1704890703234.png

 



Result:

SaurabhGupta_0-1704890621493.png

 


Thanks and Regards,

Saurabh Gupta

Amit Verma
Kilo Patron
Kilo Patron

Hi @Martin45 

 

If you want to fetch the Business Rule via script, you can use below logic :

 

var Headers = ["Name","Table","Description"];
var fileName = 'BusinessRules.csv';
var csvData = '';
for (var i = 0; i < Headers.length; i++) { 
	csvData = csvData + '"' + Headers[i] + '"' + ',';
}
csvData = csvData+"\r\n";
var gr = new GlideRecord('sys_script');
gr.addActiveQuery();
gr.query();
while(gr.next()){
csvData = csvData + '"' + gr.name + '",' + '"' + gr.collection+ '",' + '"' + gr.description+'"';
csvData = csvData+"\r\n";
}
var grRec = new GlideRecord("incident");
grRec.addQuery("sys_id","sys_id of a test incident record");
grRec.query();
if(grRec.next()){
var grAttachment = new GlideSysAttachment();
grAttachment.write(grRec,fileName, 'application/csv',csvData);
}

 

This will generate a csv file on the test incident provided as an input and you can download that to proceed. Also, if you want more columns to be added, that could be done by tweaking the csv headers and the data fetch logic.

 

Thanks & Regards

Amit Verma


Please mark this response as correct and helpful if it assisted you with your question.