Discovery Source when multiple sources apply to a CI

Sam Ogden
Tera Guru

Hi all,

We already had several data sources importing into our CMDB.  We have recently now got ServiceNow discovery also discovering CIs.

For some CI's we have SNOW integration creating the CIs so the discovery source is SnowSoftware.  These have since then been discovered by ServiceNow discovery which has updated the discovery Source to ServiceNow.  Since purchasing Discovery, we are limiting which attributes SNOW can update, however when it updates these attributes it is setting the discovery source back to SnowSoftware.  In the SNOW transform map there is a field map between the source u_discoversource and the target discovery_source.

I've tried to update this to the a source script as so:

answer = (function transformEntry(source) {
    var discoverySource = source.u_discoverysource;
    gs.info('---> SNOW Transform - Discovery Source: ' + discoverySource);
    var snowID = source.u_id;

    var computer = new GlideRecord('cmdb_ci_computer');
    computer.addQuery('x_snsab_snow_sam_i_snow_computer_id', snowID);
    computer.query();
    if (computer.next()) {
        gs.info('---> SNOW Transform - Found CI');
        if (computer.u_servicenow_discovered == true) {
            gs.info('---> SNOW Transform - SN Discovered');
			return;
        } else {
            gs.info('---> SNOW Transform - NOT SN Discovered');
            return discoverySource;
        }
    } else {
        return discoverySource;
    }

})(source);

I can see in the logs that it is finding the computer records, but it is not updating the discovery source when expected to.

We only want the discover source to be SnowSoftware when it creates the CI.  Once that CI has been discovered by ServiceNow discovery the discovery source should become ServiceNow and should remain as ServiceNow.  SNOW should be able to update the 4 attributes we have defined but when updating we don't want the discovery source to be changed, how can this be managed?

Thanks

Sam

4 REPLIES 4

Scott Halverso1
Mega Guru
Mega Guru

Could you do an onBefore script and skip all the logic you have?

if(action=='insert'){
  target.discovery_source = 'SnowSoftware';
}

 

Hi Scott,

Thanks for this.  We would need it to work on updates too.  Some of the CI's get manually created before being picked up by SNOW.

Thanks

G_30
Tera Contributor

Hi Sam,

 

Did you try .update()?

and did you ever find a way to solve this?

ersureshbe
Giga Sage
Giga Sage

Hi, I recommend what value showing in sys_created_by field under import set table based on that define the manipulation and set the Discovery Source field.

Regards,
Suresh.