Using Eval.js and Custom Mapping to modify data at sync time

Created: 2015-03-12 12:38:30
Modified: 2021-02-25 16:09:48
Tags: Custom Mapping Javascript UnitySync

By default, your UnitySync connection (and default mapping) syncs data to the Destination exactly how it appears on the Source. Occasionally, you may have need to massage the data. There is limited data massage capability in the form of the scripting. This script allows you to define specific replacement definitions.

For UnitySync v2.3 and earlier, perl and eval.pl are needed. If you have a new scripting requirement, please refer to this article which details your need to upgrade.

As of UnitySync v2.4 you will use Javascript instead. Below are instructions for implementing eval.js using a sample subroutine and custom mapping. For more Javascript information, refer to the Javascript section of our Knowledge Base.

The details below pertain only to Javascript for use with UnitySync v2.4 or later.

In \UnitySync-v2.4\global, you will find the sample file:
eval-example.js

Copy this file to eval.js, then right-click to open and edit your eval.js. You will see the sample subroutines. We’ll look at smtp_domain as an example.

smtp_domain

This subroutine will take the input value (an email address) and return the hostname (everything after the @ character).

function smtp_domain(smtpaddr)

{
    var parts=smtpaddr.split('@');
    return parts[1]===undefined ? '' : parts[1];
}

Sample mapping: extensionAttribute1=&smtp_domain('^mail^');&

slice

You may also assign a single value as seen in this simple example to assign the last 4 digits of a phone number to description attribute:

description=&'^telephonenumber^'.slice(-4);&

The scripting may also be used in a more complicated mapping, like the following that will similarly take the last 4 digits of phone number and append them to the name parts as mapped:

description= ^givenname#1^.^sn^ - &'^telephonenumber^'.slice(-4);&

Result:
description: S.Smith - 2589

Share this article:
Knowledgebase

Directory
  1. Directify - Self Service

  2. Mimic - Replication

  3. UnitySync - Sync
Password
  1. emPass - Sync
Obsolete
  1. Profiler
  2. SimpleSync