- 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
11-30-2023 09:17 AM
Hi @apbalaban ,
You can try to configure the choice value reject in Field mapping, the entire record will not process.
-Thanks,
AshishKMishra
Please mark this response as correct and helpful if it helps you can mark more that one reply as accepted solution
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-01-2023 12:20 AM
Hi @AshishKM,
thank you for your response. In my case for both CI and Contract it is "create" now, and I need to create those record if they are correct and sys_id return in not null, it's not like I don't need them at all and therefore select "reject", I just want to do additional check if the value returned in GlideRecord is not null or smth like that.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-01-2023 06:39 AM - edited 12-01-2023 06:40 AM
Hi @apbalaban ,
Did you try with "reject" option or not. I believe this transform map is for target table ( m2m ) where CI & Contract both are reference column, means both information already there in system and if CI is not found in system, we don't want to create mapping record in m2m table , so choose the option reject that particular record to be insert in m2m table.
I see you share the ignore = true , that will also ignore that record and not insert the other column for same record.
Please mark this response as correct and helpful if it helps you can mark more that one reply as accepted solution
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-30-2023 09:18 AM
HI @apbalaban ,
I trust you are doing great.
Please find the below updated script:
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;
} else {
ciSysId = "NO_MATCH"; // Indicates no match found
}
return ciSysId;
})(source);
Was this answer helpful?
Please consider marking it correct or helpful.
Your feedback helps us improve!
Thank you!
Regards,
Amit Gujrathi