Ignore Field Map Script

TramaineM
Kilo Sage

Hi, I'm trying to create a field map in our internal database employee import that will skip updating the first and last name fields if the user contains a user_name in ServiceNow. The reason for this is not all users will have a user_name or email address, but the ones who do, will have the first & last names updated from Azure if it changes. 

 

Here is the source script I have for the last_name field on the sys_user table that is still updating the field regardless of user_name:

 

answer = (function transformEntry(source) {

    var name1 = source.u_last_name;
    if (target.user_name.nil)
        return name1; // return the value to be put into the target field
    else
        ignore == true;

})(source);

 

9 REPLIES 9

Jaspal Singh
Mega Patron
Mega Patron

hi Tramaine,

 

Can you try below

answer = (function transformEntry(source) {

    var name1 = source.u_last_name;
    if (target.user_name==''){
        return name1; // return the value to be put into the target field
}
    else{
       //do nothing
}

})(source);

Hi Jaspal,

Thanks for the response. This is similar to a previous script I tried. I just tried it and it changes the last names to "undefined", ex. John undefined

Gunjan Kiratkar
Kilo Patron
Kilo Patron

Hi @TramaineM ,

Can you try below script :

answer = (function transformEntry(source) {
    var name1 = source.u_last_name;
    if (target.user_name==''){
        if(name1!=''){
            return name1; // return the value to be put into the target field if name1 is not empty
            }
            }
            
})(source);

Please Mark My Response as Correct/Helpful based on Impact
Regards,
Gunjan Kiratkar
2X ServiceNow MVP
Community Rising Star 2022
Youtube : ServiceNow Guy

Hi @Gunjan Kiratkar,

Same issue as above. It's changing the last name of all users with a user_name to undefined.

2023-08-28 12_48_28undefined _ User _.png