- Mark as New
 - Bookmark
 - Subscribe
 - Mute
 - Subscribe to RSS Feed
 - Permalink
 - Report Inappropriate Content
 
06-15-2025 09:28 PM
Hi All,
I have written the script in the field mapping of the transform map but it is not going to else part , Can anyone help me to resolve this issue.
Solved! Go to Solution.
- Mark as New
 - Bookmark
 - Subscribe
 - Mute
 - Subscribe to RSS Feed
 - Permalink
 - Report Inappropriate Content
 
06-15-2025 09:35 PM
did you print what came in that value?
try this and share
var managedBy = source.u_managedby;
gs.info('managed by ' + managedBy);
if (managedBy != '' && managedBy != undefined) {
    gs.log('Ki_123' + managedBy);
    var usr = new GlideRecord('sys_user');
    usr.get('u_ad_distinguished_name', managedBy);
    return usr.sys_id;
} else {
    gs.log('Ki_124' + managedBy);
    return "";
}
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
 - Bookmark
 - Subscribe
 - Mute
 - Subscribe to RSS Feed
 - Permalink
 - Report Inappropriate Content
 
06-15-2025 09:34 PM - edited 06-15-2025 09:34 PM
Hi @chandan2212 ,
managedBy is not actually an empty string ('') — it could be:
undefined
null
A string with spaces (e.g., ' ')
A non-empty string that evaluates falsy only under specific conditions
var managedBy = source.u_managedby;
if (managedBy && managedBy.trim() !== '') {
gs.log('Ki_123: ' + managedBy);
var usr = new GlideRecord('sys_user');
if (usr.get('u_ad_distinguished_name', managedBy)) {
return usr.sys_id;
} else {
gs.log('Ki_125: No user found for DN ' + managedBy);
return '';
}
} else {
gs.log('Ki_124: managedBy is empty or undefined. Value: [' + managedBy + ']');
return '';
}
Please mark my answer as helpful/correct if it resolves your query.
Regards,
Arun Manoj
- Mark as New
 - Bookmark
 - Subscribe
 - Mute
 - Subscribe to RSS Feed
 - Permalink
 - Report Inappropriate Content
 
06-15-2025 09:35 PM
did you print what came in that value?
try this and share
var managedBy = source.u_managedby;
gs.info('managed by ' + managedBy);
if (managedBy != '' && managedBy != undefined) {
    gs.log('Ki_123' + managedBy);
    var usr = new GlideRecord('sys_user');
    usr.get('u_ad_distinguished_name', managedBy);
    return usr.sys_id;
} else {
    gs.log('Ki_124' + managedBy);
    return "";
}
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
 - Bookmark
 - Subscribe
 - Mute
 - Subscribe to RSS Feed
 - Permalink
 - Report Inappropriate Content
 
06-15-2025 09:35 PM
Hi @chandan2212 
If you are using this in Transform Script: 
var managedBy = source.u_managedby;
if (!gs.nil(managedBy)) {
    gs.log('Ki_123: ' + managedBy);
    var usr = new GlideRecord('sys_user');
    usr.addQuery('u_ad_distinguished_name', managedBy);
    usr.query();
    if (usr.next()) {
        target.u_managed_by = usr.sys_id.toString(); // set target field (or whichever you're mapping to)
    } else {
        gs.log('Ki_125: No user found for ' + managedBy);
        target.u_managed_by = ""; // or leave unset
    }
} else {
    gs.log('Ki_124: ManagedBy is empty');
    target.u_managed_by = ""; // or null
}
Please Mark this Helpful and Accepted Solution. If this Helps you to understand. This will help both the community and me..
- Keep Learning 
Thanks & Regards 
Deepak Sharma 
