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

Adam Stout
ServiceNow Employee
ServiceNow Employee

While this may introduce upgrade issues in the future, you can add sys_id to the slush bucket by editing the "Fields" field on the Scripts form and set this attribute:


include_sys_id_in_fieldlist=true


This should then give you the choice to select sys_id as a field to pass on every table.


Hi Adam,



I added the attribute in the Dictionary for the "Fields" field, but it's not showing the Sys_id in the slush bucket.


The attribute is not stored in the Related list for the field "Fields" too. Normally if you add an attribute manually in the attribute field, ServiceNow is generation automatically a record in the Attribute Related list, but this one is not recognizable.


I wasn't aware of Adams workaround, in my Instance it worked the other way around, adding the attribute via related list.


What version are you on?   I believe I tested this on Jakarta, but not sure about previous versions.


I'm on Istanbul Adam