Sohail Khilji
Kilo Patron
Kilo Patron

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 ?

 

SohailKhilji_0-1704868085957.png

 

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.

SohailKhilji_0-1704866994814.png

 

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)

SohailKhilji_1-1704867254805.png

 

 

 

 

(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://www.servicenow.com/community/itom-forum/update-discovery-schedule-name-when-the-ci-is-update...

https://support.servicenow.com/kb?id=kb_article_view&sysparm_article=KB0820001

https://www.servicenow.com/community/itom-forum/how-to-pass-discovery-schedule-fields-to-a-ci-record...

Thanks to : @shloke04 @MattSN @Rahul Priyadars

 

  <<<  Top Articles  >>>

  1. ServiceNow Integration with Splunk
  2. LDAP Integration with ServiceNow
  3. ServiceNow Integration with Veeam
  4. Handling ServiceNow flow errors with a flow
  5. Show parent child incident relationships - display in field message
  6. ServiceNow SSO Logout Error (redirects to logout page) – Reason, Fixes and Cause.
  7. Multi Row Variable set ServiceNow MRVS - Creating - Scripting - Example - Limits
  8. ServiceNow Integration with MAC vendor - Get Mac vendor for the given MAC Address.
  9. How to find Log4j vulnerable severs in ServiceNow Using CMDB Query Builder (SecOps) 
  10. How to Cancel a Long-Running Transaction ServiceNow
  11. Hidden Features for System Administrators
  12. Servicenow RPA - Understanding Attended / Unattended / Skilled Automation Bots
  13. Servicenow vCenter Discovery | Step by step Discovering VMware using vCenter Discovery. 

 

MF Sohail Khilji | Servicenow Developer /  Consultant.

LinkedIn >   https://www.linkedin.com/in/mf-sohail-khilji/

Version history
Last update:
‎01-09-2024 10:34 PM
Updated by:
Contributors