CMDB: Consider Script in Transform Map while using "Identification and Reconciliation framework"

MarcB1
Tera Guru

Hi

I added the code from https://developer.servicenow.com/app.do#!/api_doc?v=geneva&id=r_CMDBTransformUtil-CMDBTransformUtil   to a "onBefore" Transform Map Script.

It workes very well, but unfortunately it ignores the Transform Map Script itself (the onBefore works fine)

In the Script I usually enrich various CI attributes based on fields I read from SCCM. e.g. set Company based on the Domain Name.

Any advice?

BTW: very good examples https://community.servicenow.com/docs/DOC-6808

SCCM 2012 Computer Identity _ IT Service Management - Google Chrome 2017-05-26 19.57.43.png

onBefore _ IT Service Management - Google Chrome 2017-05-26 19.59.51.png

16 REPLIES 16

So as I understand in your source script you are trying to use the "name" value to extract out the sys_id of the reference field (like manufacturer), right?



I created a simple transform map on demo instance "demonightlyjakarta", and used below source script to populate the target manufacturer field. Field mapping is used in conjunction with CMDBTransformUtil. It worked fine and the source script successfully ran and mapped manufacturer name value to its sys_id and populated in the target field.



Source Script on manufacturer field:


answer = (function transformEntry(source) {


var myValue = "";


      var gr = new GlideRecord("core_company");


      gr.addQuery("name", source.u_manufacturer);


      gr.query();


      if(gr.next()) {


          myValue = gr.getValue("sys_id");


      }


return myValue; // return the value to be put into the target field


})(source);



Key things you should check:


1. Ensure your source script is correct and is correctly setting the answer value as in sample source script above.


2. Ensure that your sys_ids returned by mm.getModelNameSysID() and mm.getManufacturerSysID() are valid sys_ids that exists.


Hi Manish



Maybe there is some confusion. Sandesh and I talk about the Transform Map script itself (Not the source scripts for each field mapping entry).


Maintaining one script is much much easier than split it into different source scripts (they have a lot decision logic in common which would lead to code duplication).



find_real_file.png


manishgupta
ServiceNow Employee
ServiceNow Employee

Ok understood, please note currently we support running such script at field map level, not at the table map level.



We will need to add support for running such script at table map level in future releases.


manishgupta
ServiceNow Employee
ServiceNow Employee

Also, as a work around till we add that support, have you tried running your above runIT() code in onBefore() script just before you call CMDBTransformUtil().


manishgupta
ServiceNow Employee
ServiceNow Employee

I tested the work around of running such code in onBefore() script just before you call CMDBTransformUtil(). And it works.



Just note that this is a work around and the additional code that you add will have the source field itself set with newValue (source.u_manufacturer = newValue) and not the target field. Look at the example code added in onBefore script below:



Example:


(function runTransformScript(source, map, log, target ) {


     


      // Additional code


      var newValue = "";


      var gr = new GlideRecord("core_company");


      gr.addQuery("street", source.u_manufacturer);


      gr.query();


      if(gr.next()) {


          newValue = gr.getValue("sys_id");


      }      


      source.u_manufacturer = newValue;


     


    // CMDBTransformUtil code


    var cmdbUtil = new CMDBTransformUtil();


    cmdbUtil.identifyAndReconcile(source, map, log);


    ignore = true;



})(source, map, log, target);