The CreatorCon Call for Content is officially open! Get started here.

CI Location getting updated from SN discovery

gautamchawak
Kilo Explorer

When discovery is run, does it also update the location field on CI. I am experiencing this issue where discovery is trying to update the location field with the value given in discovery schedule for the CI being discovered. Is this the expected behaviour? If yes, how do I disable updation to location field from discovery.

2 REPLIES 2

Mark Stanger
Giga Sage

Just leave the location field blank on the discovery schedule if you don't want it recorded on the CI.

http://wiki.servicenow.com/index.php?title=Discovery_Schedules


kumar37
Kilo Contributor

Hi all,

am new to service now.please accept my apologies if there is anything wrong in the code.

i have the similar requirement,based on my understanding i have written the below code. but it is not giving the expected output. can any one please help me on this.

below are the requirement details and written code.

I have a requirement to update the location of the server in CMDB_CI_SERVER table w.r.to discovery schedule location.

We have OOB feature to update the location, but for some servers location is not updating, so we want to customize this.

1)   Discovery schedule has location field with one value, the same should be updated for servers in CMDB_CI_SERVER table w.r.to their IP ranges.

2) For every discovery schedule we have defined some IP ranges .the server which is present in the above tables IP range will fall in the defined range.

I have written below business rule for this .script is executing fine, but location is not populating in the CMDB_CI_SERVER table.

 

Business rule:

 

function location(){

var sysID ='8d7eb7ed4f302e842967ef4f0310c789';  

var serverip = new GlideRecord('cmdb_ci_server');

serverip.addQuery('sys_id',sysID);

serverip.Query();

while(serverip.next()){

var iprange = new GlideRecord('discovery_range_item');

var discsche = new GlideRecord('discovery_schedule');

if( serverip.getValue('ip_address') >= iprange.getValue('start_ip_address')   && serverip.getValue('ip_address') <= iprange.getValue('end_ip_address') ){

    answer = iprange.getValue('schedule');

    gs.log('answer');

    continue;  

  }

  if( answer = discsche.getValue('name')){

      answer2   = discsche.getValue('location');

    continue;  

  }

  if( answer2 != serverip.getValue('location')){

    answer3 = answer2;

  }

    serverip.location= answer3;

serverip.update();

  }

  }

 

 

Thanks,

kumar