
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-22-2019 06:59 AM
Hello SN Experts,
I'm trying to make a Transform Map using source script for one field.
The target field is a 'List field' type and what I what to do is fill this field with data from the source.
Down below, is the script that i made.
What I'm trying to do is create a array variable (osg) where all data from the 'list field' source type are stored, then within a 'forEach' loop I go through every element and for each I create a GlideRecord to the "sys_user_group" table and add the following query(because the data from the source is related to the "sys_user_group" table). The last step is set the output variable 'answer' to the ''sys_id".
the problem is when I run the transform map, it does nothing for the target field.
answer = (function transformEntry(source) {
// Add your code here
var osg_array = source.u_other_support_group.split(',');
var cont = 1;
osg_array.forEach(function(element){
var gr = new GlideRecord('sys_user_group');
gr.addQuery('name',String(element).trim());
gr.setWorkflow(false);
gr.query();
if(gr.next()){
if(cont < osg_array.length)
answer = gr.sys_id + ',';
else
answer = gr.sys_id;
return answer;
}
cont++;
});
//return answer; // return the value to be put into the target field
})(source);
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-22-2019 11:18 AM
I think your "return answer" line is being called as a part of the function instead of for the script as a whole. I also did a bit of other cleanup. Try the below and let me know if it works or not
answer = (function transformEntry(source) {
// Add your code here
var osg_array = source.u_other_support_group.split(',');
var ans = [];
osg_array.forEach(function(element){
var gr = new GlideRecord('sys_user_group');
gr.addQuery('name',String(element).trim());
gr.query();
if(gr.next()){
ans.push(gr.getValue("sys_id"));
}
});
return ans.join(","); // return the value to be put into the target field
})(source);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-22-2019 11:18 AM
I think your "return answer" line is being called as a part of the function instead of for the script as a whole. I also did a bit of other cleanup. Try the below and let me know if it works or not
answer = (function transformEntry(source) {
// Add your code here
var osg_array = source.u_other_support_group.split(',');
var ans = [];
osg_array.forEach(function(element){
var gr = new GlideRecord('sys_user_group');
gr.addQuery('name',String(element).trim());
gr.query();
if(gr.next()){
ans.push(gr.getValue("sys_id"));
}
});
return ans.join(","); // return the value to be put into the target field
})(source);

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-23-2019 12:50 AM
Thanks you a lot Troy, your solution works very good!!