Change field that discovery updates for location?

Conan_Lloyd
Mega Expert

For reasons I can't go into we need discovery to no longer update the location field but update a new field called Discovered Location u_discovered_location.   I can't find the script I need to update.   Can anyone help me out?

1 ACCEPTED SOLUTION

prdelong
Kilo Guru

If you don't want to modify the Shazzam probe, you can also put an "after" business rule on the 'discovery_device_history' table. It holds the CI in a reference field and you can dot-walk to the Discovery Schedule table. Of course that doesn't prevent the location form being written to the location field on the CI record, but I know a lot of clients have been hesitant to modify the OOB probes/sensors. You can set the location record to NULL and erase that value if you want though (or write another BR to reject any update to the location field).



conditions: !current.cmdb_ci.nil() && current.cmdb_ci.changs()



addLoc();



addLoc(){



var sysID = current.cmdb_ci;



var newLoc = new GlideRecord('cmdb_ci_hardware');


newLoc.addQuery('sys_id',sysID);


newLoc.query();



if(newLoc.next()){


        //gs.log("Location name is: " + current.status.dscheduler.location);


        newLoc.u_discovered_location = current.status.dscheduler.location;


        //newLoc.location = NULL;


        newLoc.update();


}



View solution in original post

7 REPLIES 7

Marcus Fly
Tera Expert

This should be in the Shazzam Sensor script.   If you scroll down there is a function called "updateLocation".



Hope this helps.



      updateLocation: function() {


              if (!this.schedule.location)


                      return;




              this.ciData.getData()['location'] = this.schedule.location;


      },


If you do modify the Shazzam sensor probe, I recommend copying it and marking the original as "active = false" so that you'll still get future updates to Shazzam.



(Apologies if I'm already telling y'all something you know.)


prdelong
Kilo Guru

If you don't want to modify the Shazzam probe, you can also put an "after" business rule on the 'discovery_device_history' table. It holds the CI in a reference field and you can dot-walk to the Discovery Schedule table. Of course that doesn't prevent the location form being written to the location field on the CI record, but I know a lot of clients have been hesitant to modify the OOB probes/sensors. You can set the location record to NULL and erase that value if you want though (or write another BR to reject any update to the location field).



conditions: !current.cmdb_ci.nil() && current.cmdb_ci.changs()



addLoc();



addLoc(){



var sysID = current.cmdb_ci;



var newLoc = new GlideRecord('cmdb_ci_hardware');


newLoc.addQuery('sys_id',sysID);


newLoc.query();



if(newLoc.next()){


        //gs.log("Location name is: " + current.status.dscheduler.location);


        newLoc.u_discovered_location = current.status.dscheduler.location;


        //newLoc.location = NULL;


        newLoc.update();


}



Hi prdelong,



Thanks for the info. Do we need to write a business rule on 'discovery_device_history' table if we want discovery to prevent updating particular field on the record for the specific class ?



Thanks!



Regards,


Sunil Safare