We're reclaiming inactive PDIs to keep them available for active builders. Learn what's changing, who's affected, and how to protect your work. Read More

in the script else part is not going

Not applicable

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.

var managedBy=source.u_managedby;
if(managedBy != '')
    {
        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 "";
    }
 
Thanks,
Chandan 
1 ACCEPTED SOLUTION

Ankur Bawiskar
Tera Patron

@Community Alums 

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.

Regards,
Ankur
Certified Technical Architect  ||  10x ServiceNow MVP  ||  ServiceNow Community Leader

View solution in original post

3 REPLIES 3

armanoj
Mega Sage

Hi @Community Alums ,

 

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

Ankur Bawiskar
Tera Patron

@Community Alums 

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.

Regards,
Ankur
Certified Technical Architect  ||  10x ServiceNow MVP  ||  ServiceNow Community Leader

Deepak Shaerma
Mega Sage

Hi @Community Alums 

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