How does one obtain the sys_id of the device being discovered in the Sensor?

Michael Zglesze
Giga Expert

Hello Community!

I am writing a custom Sensor for a cluster of clusters that is incorporated within my company's infrastructure.   I'm having a lot of trouble refering to the Solaris Server that is currently being discovered as I cannot find a way to get the sys_id.   I've tried using the objects "current" and "this" and "result" and the function getValue() and none of them return anything useful.   For example, the following code in the custom Sensor returns the following output (this is just the way I'm testing and debugging as I am not an admin):

new DiscoverySensor({
        process: function(result) {
                  var theSysID = current.getValue('sys_id');    
                  current.u_ci_description = "SysID from Sensor:   " + theSysID +
                                                                    "\n\nTHIS:   " + JSON.stringify(this) +
                                                                    "\n\nCURRENT:   " + JSON.stringify(current) +
                                                                    "\n\nRESULT: " + JSON.stringify(result);
        },

        type: "DiscoverySensor"
});

Note that I can write to the record using the "current" object, when I try to use current.sys_id or current.getValue('sys_id'), or the "this" or "result" objects, I get "undefined" or "null" or empty sets or information that I don't need:

SysID from Sensor:   undefined

THIS:   {"cache":{},"relatedListdataObj":{},"errorMap":{},"warningMap":{},"_defaultSave":true,"_debug":null,"_deviceCi":null,"_ciSchema":null,"type":"DiscoverySensor","ciData":{"ignoreFields":{"sys_created_by":true,"sys_updated_by":true,"sys_mod_count":true},"GlideRecordUtil":{},"debug_flag":false,"data":{},"rl_map":{},"cmdb_ci":null,"related":{}},"ci_data":{}}

CURRENT:   {}

RESULT: {"output":"redacted information"}

Does anyone know how to get the unique identifier of the CI currently being discovered?

Thanks

1 ACCEPTED SOLUTION

Dave Ainsworth
ServiceNow Employee
ServiceNow Employee

Hi Michael,



You can probably use the following:



var deviceGR = this.getCmdbRecord();


current.u_ci_description = "SysID from Sensor:   " + deviceGR.sys_id +



There is some documentation on the developer site for DiscoverySensor:



https://developer.servicenow.com/app.do#!/api_doc?v=jakarta&id=r_DSEN-getCmdbRecord



Regards,



Dave


View solution in original post

3 REPLIES 3

Dave Ainsworth
ServiceNow Employee
ServiceNow Employee

Hi Michael,



You can probably use the following:



var deviceGR = this.getCmdbRecord();


current.u_ci_description = "SysID from Sensor:   " + deviceGR.sys_id +



There is some documentation on the developer site for DiscoverySensor:



https://developer.servicenow.com/app.do#!/api_doc?v=jakarta&id=r_DSEN-getCmdbRecord



Regards,



Dave


Thank you, David!   This is exactly what I was looking for!!  


Aditya Telideva
ServiceNow Employee
ServiceNow Employee