Pre-Post Processing Script - To perform lookup on a reference field
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-03-2025 05:08 AM - edited ‎04-03-2025 05:10 AM
Hello, I will start off by saying that my scripting skills are probably my weakest area in ServiceNow. I have a scenario where I have created a custom Discovery Pattern that is discovering an HP iLO (physical card installed on a server that allows remote management/console) via HTTP and creating an out-of-band device, this is working as intended. However, I would also like to perform a lookup against another table (potentially cmdb_ci_computer) and populate the host field on the cmdb_ci_outofband_device table. For example, if I am able to discover an HP ilo Device, name:hp_ilo and this device resides on a server, name:ilo_host. I would want to populate the hostfield in the screenshot with the server name. I believe this can be accomplished by a pre-post processing script. I am not exactly sure where to start or how to accomplish this. Thanks in advance for any advice or assistance.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-03-2025 05:36 AM
Hello @gagribben
Use below post-processing script -
// Get the discovered HP iLO device name var iloDeviceName = current.name; // Lookup the server name in the cmdb_ci_computer table var computerGR = new GlideRecord('cmdb_ci_computer'); computerGR.addQuery('name', iloDeviceName); computerGR.query(); if (computerGR.next()) { // Populate the host field in the cmdb_ci_outofband_device table var outOfBandDeviceGR = new GlideRecord('cmdb_ci_outofband_device'); outOfBandDeviceGR.get(current.sys_id); outOfBandDeviceGR.host = computerGR.name; outOfBandDeviceGR.update(); }
Please change names of all fields as it is in your system.
Kindly mark my answer as helpful and accept solution if it helped you in anyway. This will help me be recognized for the efforts and also move this questions from unsolved to solved bucket.
Regards,
Shivalika
My LinkedIn - https://www.linkedin.com/in/shivalika-gupta-540346194
My youtube - https://youtube.com/playlist?list=PLsHuNzTdkE5Cn4PyS7HdV0Vg8JsfdgQlA&si=0WynLcOwNeEISQCY
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-03-2025 06:17 AM - edited ‎04-03-2025 06:19 AM
@Shivalika Thank you very much for the quick response. I wanted to confirm with you before I started testing. There are 2 CIs involved here.
- A server (cmdb_ci_computer) that is being discovered
- A HP iLO console card.
My custom discovery pattern is fundamental, with only 4 total steps.
- Get the server that is hosting the HP iLO name (the value that should be populated in the Host field of the cmdb_ci_outofband_device ci) and assign the variable with Regular Expression Parsing
- Varible = sysHost
- Update the Host field on the cmdb_ci_outofband_device CI with the previously defined variable
- Value = $sysHost
- Name = $cmdb_ci_outofband_device[*].host
- Get the HP iLO name (the value that should be populated in the Name field of the cmdb_ci_outofband_device ci) and assign the variable with Regular Expression Parsing
- Variable = sysName
- Update the Name field on the cmdb_ci_outofband_device CI with the previously defined variable
- Value = $sysName
- $cmdb_ci_outofband_device[*].name
This is currently working when debugging/testing the discovery pattern. I think the issue I am running into is the reference field (host) is expecting a sysid and not a string for the record in cmdb_ci_computer table. I have confirmed this by hardcoding a sysid in its place, and the Host reference field will be updated with the host name of the sysid associated cmdb_ci_computer record.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-03-2025 06:19 AM
Hello @gagribben
Yes you are right in this aspect, it's because of that.
Kindly mark my answer as helpful and accept solution if it helped you in anyway. This will help me be recognized for the efforts and also move this questions from unsolved to solved bucket.
Regards,
Shivalika
My LinkedIn - https://www.linkedin.com/in/shivalika-gupta-540346194
My youtube - https://youtube.com/playlist?list=PLsHuNzTdkE5Cn4PyS7HdV0Vg8JsfdgQlA&si=0WynLcOwNeEISQCY
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-03-2025 06:36 AM
@Shivalika, If I am understanding this correctly, step 2 should be removed in place of a post-processing script. In the script, we would do a lookup for the value returned and assigned to sysHost in step 1 against the cmdb_ci_computer table and only return the sysID. Then set that sysID as the value in the Host reference field? Is it possible?