How to debug a script source code in a transform amp

johannes5
Giga Expert

Hi ServiceNow Community Developers,

I have a transform map where the source field is from a script i.e. in the Source for that field I checked the 'Use source script' checkbox so that the value to be mapped to the target field comes from a script. The problem I am running into is it's not working and I cannot even tell if my script is running at all. I have some debug code there (gs.log) and I cannot see it. I am assuming that this kind of script in a transform map is server side code and therefore I should see my gs.log statements in the logs if it's running but I don't see anything. Do you guys know what is the best way to debug a source script in the transform map?

Here is my source script code and I know that it works because I first tested it as a schedule job and I then replaced the calling object with source. Please take a look and advise.

answer = (function transformEntry(source) {

  // Add your code here

gs.log ("inside map script");

var fullEmpId = '';

if (source.u_employeeid.toString().length < 6) {

  if (source.u_employeeid.toString().length == 5) {

  fullEmpId = '0' + source.u_employeeid;

  }

  else if (source.u_employeeid.toString().length == 4) {

  fullEmpId = '00' + source.u_employeeid;

  }

  else if (source.u_employeeid.toString().length == 3) {

  fullEmpId = '000' + source.u_employeeid;

  }

  else if (source.u_employeeid.toString().length == 2) {

  fullEmpId = '0000' + source.u_employeeid;

  }

  else if (source.u_employeeid.toString().length == 1) {

  fullEmpId = '00000' + source.u_employeeid;

  } else {

  fullEmpId = source.u_employeeid;

  }

  } else {

  fullEmpId = source.u_employeeid;

  }

gs.log ('employee id' + fullEmpId);

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

})(source);

1 ACCEPTED SOLUTION

ashwinkumar_pat
Giga Expert

Hi Johannes



gs.log() should work.



Where are you looking for your log statements?


Is it the field mapping script or transform event script?


View solution in original post

3 REPLIES 3

ashwinkumar_pat
Giga Expert

Hi Johannes



gs.log() should work.



Where are you looking for your log statements?


Is it the field mapping script or transform event script?


Hi Ashwinkumar,



I am checking for my log statements in the Script Log Statements under the System Log application. Yes this is a field mapping script.



Thanks for your response.



Johannes


ok, I got it to work with the same script, no changes,in fact it was working all along I just was running it with incorrect data



Thanks,