Setting References to none CIs in a Discovery Pattern

Daniel Borkowi1
Mega Sage

Hi,

I tried to create an discovery pattern for a network device.

I read in a display value of the firmware_manufacturer via SNMP Query.

With this name I will set a reference to core_company in CI. If I write the display value in the field via pattern operation "Set Value", I get something like that:

<firmware_manufacturer display_value="">Aruba</firmware_manufacturer> after discovery.

But I want to have that: <firmware_manufacturer display_value="Aruba">sys_id_of_company</firmware_manufacturer>

How can I reach that in a pattern?

Greets, Daniel

2 ACCEPTED SOLUTIONS

Daniel,



Check out the blog post I just put together.



Using Pre/Post Processing Scripts to handle reference fields via Discovery Pattern



I hope this solves your issue.


View solution in original post

8 REPLIES 8

Daniel Borkowi1
Mega Sage

I temporarily solved it with a before update Business Rule. This replaces values in reference fields if it does not contain sys_ids. But I would be happier if there was something within the pattern approach.



(function executeRule(current, previous /*null when async*/) {


      //Display an information message for each change to the record


      var gru = GlideScriptRecordUtil.get(current);


      var changedValues = gru.getChangedFieldNames(); //Get changed field values


      //Convert to JavaScript Arrays


      gs.include('j2js');


      changedValues = j2js(changedValues);


      //Process the changed fields


      for(var i = 0; i < changedValues.length; i++){


              var val = current[changedValues[i]];


              var elemDesc = val.getED();


              if(elemDesc.getInternalType() == "reference" ){


                      var value = val.getValue();


                      var regexp = /([0-9a-f]{32})/;


                      if(value.match(regexp) == null){


                              current.setValue(elemDesc.getName(),"");                            


                              current.setDisplayValue(elemDesc.getName(),value);


                      }


                   


              }


      }


   


})(current, previous);



I set the value as display_value and after an update the system will replace the reference correctly with the sys_id.



Is nobody here who knows a better approach within the patterns self?


Hi Daniel,



What I have been told by SN developers, you can use either a post or pre sensor script. Pre is to mod the payload before record gets submitted to DB, Post is to update record after its been submitted to DB.



Give me a few hours and Ill update my post with examples.


Thanks for your answer Patrick. I'm looking forward for your examples.


Daniel,



Check out the blog post I just put together.



Using Pre/Post Processing Scripts to handle reference fields via Discovery Pattern



I hope this solves your issue.