How to get the sys_id of the current record in an Indicator Script?

Serkan Yilmaz
Tera Expert

Hi,

Is there a way to get the "sys_id" available in the Field (field_list) or directly in the script on the Script form in PA?

It's not possible to select "sys_id" in the available fields on the Script form in PA to use it in the Script. This is needed to query the cmdb_rel_ci for some validations for the current record.

The following structure is built in PA:

1) Created Indicator Source on Facts table: Database Instance [cmdb_ci_db_instance]

2) Created an Indicator for this Indicator Source: "# of pass DB instances for platform validation".

Indicator details:

Aggregate: SUM

Scripted: checked

Script: SH.Validate DB platform relation

Screen Shot 2017-09-05 at 09.49.28.png

Script details:

Source:

Screen Shot 2017-09-05 at 09.55.30.png

Remark: In the Available field list is sys_id not visible.

Script:

checkPlatformforDBInstance(current);

function checkPlatformforDBInstance(record){

var rValue = 0;

var sysId = record.sys_id; //sys_id is not available..

var vTable = 'cmdb_rel_ci';

var vCol;

var vStrQuery ='parent='+sysId;

if(sysId != ''){

var grVal = new GlideRecord(vTable);

grVal.addEncodedQuery(vStrQuery);

grVal.query();

while(grVal.next()){

if(grVal.child.sys_class_name == 'cmdb_ci_win_server'){

rValue = 1;

}

}

}

return (rValue);

}

Dirty workaround: There is a dirty way (add sys_id in XML and import Script record in ServiceNow) to make sys_id available in the script area, but this is not the preferred way forward.

Another approach: This report can also be created with a database view, but I don't want to do this.

Hopefully, someone is able to help me with this issue!

arnoud?

Cheers,

Serkan

9 REPLIES 9

gauravchoudhury
Tera Guru

Hi Serkan,



Use one of the following methods for locating the sys_id of a record,


  • Using the Context Menu
  • Using the Header Bar
  • Using the URL
  • Getting the sys_id in a Script


Source: Link



You can also refer to this blog for further reference.


Gaurav,


You are mentioning the sys_id of the record self, but I'm talking about the current record in the indicator.


Cheers,



Serkan


Arnoud Kooi
ServiceNow Employee
ServiceNow Employee

Serkan, If run into this issue, my workaround isn't elegant either.



find_real_file.png



I'll check with the development team and follow up.


Nice way to make Sys id available arnoud!


Sys id is with this method and XML load temporary available, after an update the value is not in place anymore...