Custom Mapping: Custom Javascript solution - Detect blank source value

Created: 2025-12-12 09:18:32
Modified: 2026-08-06 13:48:08
Tags: Custom Mapping Javascript

Prior to v4.7.30, if a source attribute is blank, no value is set on the destination. If there is already a value in the destination attribute, that existing attribute is NOT overwritten.

As of v4.7.31, if a source attribute is blank, the destination attribute will be blanked out.

The below may still be used to assign an attribute instead of blanking the destination.

Note: If this solution is needed for only a few attributes, you can consider using Option 1. For many or all attributes, use Option 2.

Option 1:

Using a Custom map file, you can use a single statement to assign a value. This would be done per attribute you wanted to affect.

This option has the limitation that if a source value contains a single quote, the syntax breaks. Therefor, if there may be a quote, you should use Option 2 instead.

company=&‘^company^’ == ‘’ \? ‘None Specified’ : ‘^company^’&

Option 2:

This option will work on any source text value (regardless of quotes it may contain).

This solution utilizes both Custom attribute mappings and a custom eval.js file.

Example Mappings

Note, the below mapping syntax does NOT include the ^ character: (‘^description^’).

description#1024=&ReplaceIfBlank(‘description’)&

company=&ReplaceIfBlank(‘company’)&

department#64=&ReplaceIfBlank(‘department’)&

Note: Department mapping is included as an example of an attribute not included in eval.us. This illustrates when an attribute will remain unchanged since it is not in eval.js.


Custom \UnitySync\global\eval.js.txt


function ReplaceIfBlank(theAttrib)
{
   // EVERY mapped attribute that calls this function MUST be included below, Else the dest value unchanged.  
   // There must be an 'if' statement for each attribute.

if (theAttrib == "description"){                            // identify the attribute passed from the map file.
    if (getsrc('description')===undefined) return "None Specified";     // if it is blank, return "None Specified"
    else return getsrc('description');                      // if not blank, return source value. 
}

if (theAttrib == "company"){
    if (getsrc('company')===undefined) return "None Specified";  // Can substitute a space " " for "None Specified"
    else return getsrc('company');                  
}

    // *If the attribute is not in this function, nothing is returned.   
    // Original dest value is unchanged.

return;  // returns nothing, original dest value remains

}

Knowledgebase

Products
  1. UnitySync - GalSync
  1. Directify - Self Service
  1. emPass - Password Sync