- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-21-2016 06:10 AM
Hi All
I have a very basic requirement of updating the Watch list of incident with a transform Map. I have created a spreadsheet with two fields incident and Name.
Incident=Used as a Coalesce Field
Name= Email address of users whom should be added in watch list.
abel.tuter@example.com;adela.cervantsz@example.com;aileen.mottern@example.com;alejandra.prenatt@example.com;alejandro.mascall@example.com |
I have written script as below
(function transformRow(source, target, map, log, isUpdate) {
// Add your code here
var name = source.u_name.toString();
var incident =source.u_incident.toString();
var split_names = name.split (";");//Breaking the input in a array
var num_names = split_names.length;
var sys_id;
for(i=0;i<=num_names;i++)
{
var gr = new GlideRecord('sys_user');
gr.get('email',split_names[0]);
gr.query();
if(gr.next())
{
target.watch_list= target.watch_list+";"+gr.sys_id;//Setting the sys_id of each email address
gs.addInfoMessage(gr.sys_id);
gs.addInfoMessage(split_name[0]);
}
}
})(source, target, map, log, action==="update");
The Data is getting updated but the data is getting as it is , its not getting processed as per the script.
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-21-2016 06:15 AM
Hi Avinash, I'm sure you'll have a lot of responses to this.
Here's my quick glance at it and a couple changes to make.
Change your for loop to be <, not <=, or you will get an extra undefined result
Change your target.watch_list assignment to this
target.watch_list= target.watch_list+","+gr.getValue('sys_id');
watch lists are comma separated, not colon.
(function transformRow(source, target, map, log, isUpdate) {
// Add your code here
var name = source.u_name.toString();
var incident =source.u_incident.toString();
var split_names = name.split (";");//Breaking the input in a array
var num_names = split_names.length;
var sys_id;
for(i=0;i<num_names;i++)
{
var gr = new GlideRecord('sys_user');
gr.get('email',split_names[0]);
gr.query();
if(gr.next())
{
target.watch_list= target.watch_list+","+gr.getValue('sys_id');
gs.addInfoMessage(gr.sys_id);
gs.addInfoMessage(split_name[0]);
}
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-21-2016 06:15 AM
Hi Avinash, I'm sure you'll have a lot of responses to this.
Here's my quick glance at it and a couple changes to make.
Change your for loop to be <, not <=, or you will get an extra undefined result
Change your target.watch_list assignment to this
target.watch_list= target.watch_list+","+gr.getValue('sys_id');
watch lists are comma separated, not colon.
(function transformRow(source, target, map, log, isUpdate) {
// Add your code here
var name = source.u_name.toString();
var incident =source.u_incident.toString();
var split_names = name.split (";");//Breaking the input in a array
var num_names = split_names.length;
var sys_id;
for(i=0;i<num_names;i++)
{
var gr = new GlideRecord('sys_user');
gr.get('email',split_names[0]);
gr.query();
if(gr.next())
{
target.watch_list= target.watch_list+","+gr.getValue('sys_id');
gs.addInfoMessage(gr.sys_id);
gs.addInfoMessage(split_name[0]);
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-22-2016 06:23 AM
Thanks ctomasi
It worked like a charm, one more question How can i log all the information in transform map like in scripts if I want to log something.
logs are just useless even with lowest level. Plz help.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-22-2016 06:50 AM
Hi Avinash,
If the above script fixed your problem, don't forget to mark it correct if it resolved your issue.
Regarding logging, you can use gs.log() to record your messages to the system log. You can find the results in System Logs> Script Log Statements.
gs.addInfoMessage() is more useful for interactive sessions where you want to alert the user using a blue banner message to convey information they see. Using these in a transform map or any other script that runs in the background is not very effective.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-17-2016 07:45 AM
Hi Avinash,
I have a similar requirement which you mentioned above in this thread, Customer is asking for uploading multiple data into list field via transform map.
I guess I am facing issues while pushing the data into target.<field name>.
var srcVal = source.u_compliance_o_y_requirements.indexOf(',');
//To check if the source contains multiple values
if(source.u_compliance_o_y_requirements.nil()){
ignore = true;
}
else if(srcVal > 0 ) {
//This would suggest source contains multiple value
var srcArray = source.u_compliance_o_y_requirements.split(',');
//splitting source into different values and putting it into array list
var trgList = target.u_compliance_and_regulatory_requirements.getDisplayValue();
var trgArray = trgList.split(",");
var srcLength = srcArray.length;
var flag = "F";
gs.log(" No of iterations: " + srcLength, "PS-TR");
//Check all values in source array one by one in for i loopk
for(i=0;i<srcLength;i++){
//first source value is selected and will be checked against all target values.
for(j=o;j<trgArray.length;j++){
gs.log(j + " Record from Traget " + trgArray[j], "PS-TR");
if(srcArray[i] == trgArray[j]){
gs.log( srcArray[i] + " Match Found " + trgArray[j], "PS-TR");
flag = "T";
}
}
if(flag == "F"){
gs.log("Add Source value " + srcArray[i] +" to taget");
target.u_compliance_and_regulatory_requirements += srcArray[i];
}
flag = "F";*/
}
}
else if(srcVal<0){
target.u_compliance_and_regulatory_requirements = source.u_compliance_o_y_requirements;
}
Would you be able to assist me in