Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Transform map script for glidelist field

madanm7786
Mega Guru

Hi All,

I need to load the data from excel into glidelist field. Data in excel sheet is having multiple users(email id) with semicolon(;) and semicolon and space(; ) seperated.

I have written a transform map script. But it is not working.

Below is the piece of code used for spliting, but with no luck.

var typ= source.u_approval.toString().split(';'); //semicolon seperated

var man = typ.toString().split('; '); //semicolon and space seperated

var gr= [];

  var tp = new GlideRecord('sys_user');

  for(var i=0;i<man.length;i++){

  tp.initialize();

...............

..............

value is not loading into glidelist field.

Please help me on this.

Thanks,

Maddy

1 ACCEPTED SOLUTION

Hi,



Use trim function to remove the space instead of the above logic. Also declaring variable outside loop may cause problem. Your script should be like this:



  var final_man= source.u_approval.toString().split(';');


  var gr= [];


  for(var i=0;i<final_man.length;i++){


    var a = new GlideRecord('sys_user');


  a.addQuery('email',final_man[i].trim());


  a.query();


  if (a.next()) {


  gr.push(a.getValue('sys_id'));


  }


}


  return gr.toString();


Thank you,
Palani

View solution in original post

4 REPLIES 4

Julian Hoch
ServiceNow Employee
ServiceNow Employee

The script you posted is incomplete and missing descriptions of the variables that are used, so I cannot really tell you where your mistake is.


In general, if you want to fill a list field, you have to set it to a string that contains a comma separated list of sys_ids, so make sure the field is set correctly.


Hi Julian,



Below is my script.



  var mag= source.u_approval.toString().split(';');


  var final_man = mag.toString().split('; ');


  var gr= [];


  var a = new GlideRecord('sys_user');


  for(var i=0;i<final_man.length;i++){


  a.initialize();


  a.addQuery('email',final_man[i]);


  a.query();


  if (a.next()) {


  gr.push(a.getValue('sys_id'));


  }


}


  return gr.toString();


Hi,



Use trim function to remove the space instead of the above logic. Also declaring variable outside loop may cause problem. Your script should be like this:



  var final_man= source.u_approval.toString().split(';');


  var gr= [];


  for(var i=0;i<final_man.length;i++){


    var a = new GlideRecord('sys_user');


  a.addQuery('email',final_man[i].trim());


  a.query();


  if (a.next()) {


  gr.push(a.getValue('sys_id'));


  }


}


  return gr.toString();


Thank you,
Palani

Hi Palani,



Thanks, It worked