- 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
3 weeks ago - last edited 3 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 - last edited 4 weeks ago
Hi @chandan2212,
can you possibly explain what's wrong with your code? it's not executed or the result is not staisfactory? It needs some context to give you meaningful response, pasting a random code is not sufficient.... :((
EDIT:
And what is supposed to be the || '' part in
var owners = source.u_owner_name || '';
What do the logs give you? Shouldn't it be just "var owners = source.u_owner_name;"???
No AI was used in the writing of this post. Pure #GlideFather only
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
@GlideFather In this line :var owners = source.u_owner_name ; multple userid will come and script is giving undefined output
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
4 weeks ago
Hi @chandan2212 ,
Can you please let me know what you're getting once you're loading or running this data (I mean which log/info message the script is populating or it's not running at all).
Also, If you could share a sample data/obj of how the owners array/object is going to look like it'll be easy for me to test more & provide you with a fix soon.
where are you writing this script? Is it in the transform map run script or transform script(before, after..) or field mapping source script?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
@MadhanMaddy :this script is giving undefined output till this line gs.info('TM Owners tokens=' + arr.length); it is working but it is not going to GlideRecord
