- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-30-2023 08:54 AM
Hello,
I have a transform map where the target table is m2m table, and there are two columns (both fields in there are Reference fields):
- Configuration item (u_configuration_item) which displays the name of CI
- Contract (u_contract) which displays the Contract number (from table ast_contract).
Source table consists of two columns:
- CI Number (unique number for each CI)
- Contract short description
I'm using field maps source scripts for each field, and for CI it looks like this:
answer = (function transformEntry(source) {
var ciNumber = source.u_ci_number;
var ciSysId = "";
var ciGR = new GlideRecord('cmdb_ci');
ciGR.addQuery('u_number', ciNumber);
ciGR.query();
if (ciGR.next()) {
ciSysId = ciGR.sys_id;
}
return ciSysId;
})(source);
And code for Contract is basically the same.
I want to implement a logic (probably in Transform Script?) that in case wrong CI number or Contract short description was given in excel file (that would result in GlideRecord returning "null") it will skip this row. Or maybe the source scripts themselves can be modified, but I don't know how.
Appreciate all the help. Thank you.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-01-2023 12:50 AM
I found the answer to my question:
I created onBefore transform map script:
(function runTransformScript(source, map, log, target /*undefined onStart*/ ) {
var ciNumber = source.u_ci_number;
var ciSysId = "";
var ciGR = new GlideRecord('cmdb_ci');
ciGR.addQuery('u_number', ciNumber);
ciGR.query();
if (ciGR.next()) {
ciSysId = ciGR.sys_id;
}
if (JSUtil.nil(ciSysId))
ignore = true;
})(source, map, log, target);
I don't think it's brilliant, but it's working 🙂
Thanks to everyone who replied to me!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-01-2023 12:15 AM
Hi @Amit Gujarathi,
thank you for your response, but unfortunately it's not working. It just took NO_MATCH and pasted it in CI:
In Excel file that I was uploading I basically gave a CI wrong number like "CI0000000000000" and obviously there's no such CI in cmdb_ci, so for this case I want to skip this row, and NO_MATCH is not working as expected here.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-01-2023 12:50 AM
I found the answer to my question:
I created onBefore transform map script:
(function runTransformScript(source, map, log, target /*undefined onStart*/ ) {
var ciNumber = source.u_ci_number;
var ciSysId = "";
var ciGR = new GlideRecord('cmdb_ci');
ciGR.addQuery('u_number', ciNumber);
ciGR.query();
if (ciGR.next()) {
ciSysId = ciGR.sys_id;
}
if (JSUtil.nil(ciSysId))
ignore = true;
})(source, map, log, target);
I don't think it's brilliant, but it's working 🙂
Thanks to everyone who replied to me!