The CreatorCon Call for Content is officially open! Get started here.

Skip record if Field Maps Source Script returns null

apbalaban
Tera Expert

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.

1 ACCEPTED SOLUTION

apbalaban
Tera Expert

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!

View solution in original post

6 REPLIES 6

Hi @Amit Gujarathi
thank you for your response, but unfortunately it's not working. It just took NO_MATCH and pasted it in CI:
nomatchci.png

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.

apbalaban
Tera Expert

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!