- Post History
- Subscribe to RSS Feed
- Mark as New
- Mark as Read
- Bookmark
- Subscribe
- Printer Friendly Page
- Report Inappropriate Content
01-09-2024 10:29 PM - edited 01-09-2024 10:34 PM
Set Discovery Schedule Name to CMDB Record (via Discovery - 2 Ways)
Ever wondered which discovery schedule updates or creates your CI on CMDB table ?
How to find which Discovery Schedule updated / created the CI ?
You may Already know that there is a field on cmdb_ci table called 'Discovery Source', but this field always updates the field value as 'Servicenow' if the CI is updated by discovery. How about knowing which of your configured discovery schedules Updated the CI during discovery run ?
Any guess how you get it ?
Well, I had the same problem identifying which of my 65 Schedules updated or created the CI. Here are the 2 solution...
Method 1 :
As you already know We have a location field passed from Discovery Schedule form to identified CI record during discovery run, this is done from Script include named 'DiscoverySensor' as shown below. The below function quries the location defined in the schedule and the value is set to the CMDB record by a function called 'addDiscoveryCiStuff' in the same script include.
If in case, if you wish to pass any custom reference field or other field you can apply the above logic to do so...
Method 2 : (Which i applied on Instace)
You can create a 'Script Action' which runs after the discovery is completed as i have created below. These Script Actions are invoked by Events after the discovery is completed.
Navigate to > System Policy > Events > Script Action.
(Configure as below image)
(function() {
var comment = "Updated by schedule:" + current.status.dscheduler.name + ''; //NAME OF THE SCHEDULE
var updated_ci = new GlideRecord("cmdb_ci"); //CI WHICH IS GETTING UPDATED
if (updated_ci.get(current.cmdb_ci.sys_id)) {
updated_ci.setValue('comments', comment); //SETTING VALUE TO COMMENT FIELD WITH SCHEDULE NAME
updated_ci.update(); //UPDATE THE CI
}
}());
I have utilized the OOTB Comments field to pass the name of the discovery schedule which created/updated the CI. You can use this logic to set any fields / corrections post discovery schedule is completed.
If you found this helpfull just hit a ''Like''... or bookmark for future use....
Helpful Sources :
https://support.servicenow.com/kb?id=kb_article_view&sysparm_article=KB0820001
Thanks to : @shloke04 @MattSN @Rahul Priyadars
<<< Top Articles >>>
- ServiceNow Integration with Splunk
- LDAP Integration with ServiceNow
- ServiceNow Integration with Veeam
- Handling ServiceNow flow errors with a flow
- Show parent child incident relationships - display in field message
- ServiceNow SSO Logout Error (redirects to logout page) – Reason, Fixes and Cause.
- Multi Row Variable set ServiceNow MRVS - Creating - Scripting - Example - Limits
- ServiceNow Integration with MAC vendor - Get Mac vendor for the given MAC Address.
- How to find Log4j vulnerable severs in ServiceNow Using CMDB Query Builder (SecOps)
- How to Cancel a Long-Running Transaction ServiceNow
- Hidden Features for System Administrators
- Servicenow RPA - Understanding Attended / Unattended / Skilled Automation Bots
- Servicenow vCenter Discovery | Step by step Discovering VMware using vCenter Discovery.
MF Sohail Khilji | Servicenow Developer / Consultant.
- 1,982 Views