Custom Mapping: Custom Javascript solution - Detect blank source value
Created: 2025-12-12 09:18:32Modified: 2025-12-12 09:36:31
Tags: Custom Mapping Javascript
By design, 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.
We designed the following custom solution for a client who wanted to sync a default value if the source attribute value is blank.
Written to their specifications, we parsed the incoming attributes to set destination attributes as desired.
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
}