CMDB: Consider Script in Transform Map while using "Identification and Reconciliation framework"
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-26-2017 11:03 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-01-2017 10:54 PM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-23-2017 11:18 AM
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).
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-24-2017 08:12 AM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-24-2017 08:48 AM
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().
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-25-2017 09:47 AM
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);