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

Srikanth_Peru
Tera Guru
Tera Guru

Hi,

Can you try the below code 

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

 

Thank you ,

Srikanth

 

Unfortunately, same undefined issue as above.

TramaineM
Kilo Sage

Any thoughts on why this is populating with "undefined"?

To ignore that field updation, write return null; if the condition fails.

cocekond
Tera Contributor

Firstly you want to set a value and not to compare it so ignore = true is a correct statement and secondly as I was dealing with a similar issue, I've discovered that you can ignore the row only in the transform map itself in the main script or in a transform scripts...