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.

how to fetch Sys ID of name field

Deepa12
Tera Contributor

Hi,

please assist me to get sys_id of name field instead of string.

var configurationitem;

var gr1 = new GlideRecord('cmdb_ci_win_server');
gr1.addEncodedQuery('fqdn=' + hostname);
gr1.query();
if (gr1.next()) {
configurationitem = gr1.name;

}

2 ACCEPTED SOLUTIONS

Sandeep Rajput
Tera Patron
Tera Patron

@Deepa12 Please update your script as follows.

 

 

var configurationitem;
var gr1 = new GlideRecord('cmdb_ci_win_server');
gr1.addEncodedQuery('fqdn=' + hostname);
gr1.query();
if (gr1.next()) {
configurationitem = gr1.getValue('sys_id');
}

 

Hope this helps.

View solution in original post

shubhamdubey
Mega Sage

@Deepa12 

 

Tried this code as well 

 

var configurationitem;

var gr1 = new GlideRecord('cmdb_ci_win_server');
gr1.addEncodedQuery('host_name=P1SAP');
gr1.query();
if (gr1.next()) {
configurationitem = gr1.sys_id;


}
gs.print(configurationitem);

 

it will give you sys_id.sys_id_record.PNG

View solution in original post

2 REPLIES 2

Sandeep Rajput
Tera Patron
Tera Patron

@Deepa12 Please update your script as follows.

 

 

var configurationitem;
var gr1 = new GlideRecord('cmdb_ci_win_server');
gr1.addEncodedQuery('fqdn=' + hostname);
gr1.query();
if (gr1.next()) {
configurationitem = gr1.getValue('sys_id');
}

 

Hope this helps.

shubhamdubey
Mega Sage

@Deepa12 

 

Tried this code as well 

 

var configurationitem;

var gr1 = new GlideRecord('cmdb_ci_win_server');
gr1.addEncodedQuery('host_name=P1SAP');
gr1.query();
if (gr1.next()) {
configurationitem = gr1.sys_id;


}
gs.print(configurationitem);

 

it will give you sys_id.sys_id_record.PNG