The Zurich release has arrived! Interested in new features and functionalities? Click here for more

Help Transform Field map script not working correctly

E_19
Giga Expert

Hi All,

I hope someone can help me.

I have a transform field map script that is not working correct. What I am trying to do is iterate though the source kunden number and for all matches that are found in core company table   the corresponding sys_id is added to u_company field but the script iterates and has the same company sys id for every record. In the log file it records same sys_id but also each unique kunden number.

Need to add the field is a reference field and the Referenced value field name: u_company

Any idea why it is not return the unique sys_id for each record?

answer = (function transformEntry(source) {

  var gr1 = new GlideRecord("core_company");

  gr1.addQuery("u_company",source.u_kundennr_.toString());

  gr1.query();

  if(gr1.next()){

  target.u_company = gr1.sys_id;

  }

  gs.log("Kundennummer: " + source.u_kundennr_);

  gs.log("sys_id von ?: " + gr1.sys_id);

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

})(source);

Many Thanks,

Ellie

1 ACCEPTED SOLUTION

can you try like this


  var gr1 = new GlideRecord("core_company");


  gr1.addQuery("nr",source.u_kundennr_.toString());


  gr1.query();


  if(gr1.next()){


  target.u_company = gr1.sys_id;


// put your logs here


  }


View solution in original post

10 REPLIES 10

nthumma
Giga Guru

Can you post the screen shot of excel file you are trying to import if possible?


Hi Nich,



Of course below is an extract anonymized


Source data first col is user id second is the company id I need to match to core company table Nr column.



Screen Shot 2017-03-25 at 15.33.36.png



Many Thanks


Ellie


can you try like this


  var gr1 = new GlideRecord("core_company");


  gr1.addQuery("nr",source.u_kundennr_.toString());


  gr1.query();


  if(gr1.next()){


  target.u_company = gr1.sys_id;


// put your logs here


  }


Hi Nish,



You got me thinking there. I am still new to scripting so at times one can get lost. It isn't nr but company id field. Which I have now added and its working.



Thank you very much



Have a great weekend


Ellie