- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
4 weeks ago
Hi All,
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
4 weeks ago - last edited 4 weeks ago
@chandan2212 Could you please try the following.
answer = (function transformEntry(source) {
var owners = source.u_owner_name+'' || ' ';
if (!owners) {
gs.info('TM Owners empty');
return '';
}
var arr = owners.split(',');
gs.info('TM Owners tokens=' + arr.length);
for (var i = 0; i < arr.length; i++) {
var userVal = (arr[i] || '').trim();
if (!userVal) continue;
var userGR = new GlideRecord('sys_user');
userGR.addQuery('user_name', userVal);
userGR.setLimit(1);
userGR.query();
if (userGR.next()) {
gs.info('TM Matched user_name=' + userVal + ' -> ' + userGR.getDisplayValue());
return userGR.name.toString();
} else {
gs.info('TM No match for user_name=' + userVal);
}
}
})(source);
Here I have replaced the line return userGR.name; with return userGR.name.toString(); ideally the string conversion should force the value to be retained.
Hope this helps.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
4 weeks ago
@chandan2212 Tried running your script in background scripts and it runs just fine. Any specific issues you are facing with this script?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
4 weeks ago
@Sandeep Rajput this script not working when i am putting in the source transform map script, it is giving undefined return
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
4 weeks ago - last edited 4 weeks ago
@chandan2212 Could you please try the following.
answer = (function transformEntry(source) {
var owners = source.u_owner_name+'' || ' ';
if (!owners) {
gs.info('TM Owners empty');
return '';
}
var arr = owners.split(',');
gs.info('TM Owners tokens=' + arr.length);
for (var i = 0; i < arr.length; i++) {
var userVal = (arr[i] || '').trim();
if (!userVal) continue;
var userGR = new GlideRecord('sys_user');
userGR.addQuery('user_name', userVal);
userGR.setLimit(1);
userGR.query();
if (userGR.next()) {
gs.info('TM Matched user_name=' + userVal + ' -> ' + userGR.getDisplayValue());
return userGR.name.toString();
} else {
gs.info('TM No match for user_name=' + userVal);
}
}
})(source);
Here I have replaced the line return userGR.name; with return userGR.name.toString(); ideally the string conversion should force the value to be retained.
Hope this helps.
