Directory Wizards Inc.

Solutions For Your Directory Needs

RSS feed
Add to Google


 

Categories

Knowledgebase

Using Eval.pl and Custom Mapping to modify data at Sync time

Category:Map Files

Last Updated:2011-09-14

 

Download PDF version

 


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 a limited data massage capability in the form of the Eval.pl script. This script allows you to define specific replacement definitions.

Below are a few of the most commonly used subroutines. One or all of these subroutines may exist in your eval.pl.  The subroutines are not activated unless called via Custom Mapping. Example custom mappings are provided for each subroutine.

  1. Create the Eval.pl file:   \UnitySync\Global\eval.pl
  2. Edit Eval.pl and insert the desired subroutines.
  3. Save Eval.pl
  4. Apply the Custom Mapping to the appropriate attribute, following the examples provided

###########################################
# Sample Eval.pl -
# This entire text may be used in Eval.pl. 
# Lines preceeded by a # character are comments.
# The mappings shown must be added to your Custom Map File in order to
# apply a subroutine to the desired attribute.
###########################################

 

###########################################
# Subroutine to remove spaces from data.

sub remove_spaces
{
my $temp=$_[0];
$temp=~s/ //g;
return $temp;
}

# Sample mapping for removing Line Feeds from streetaddress attribute:
# streetaddress#1024=& remove_spaces("^streetaddress^") &


###########################################
# Subroutine to remove Line Feeds from data.

sub remove_lf
 {
   my $temp=$_[0];
   $temp=~s/\n/ /g;
   $temp=~s/\r//g;
   return $temp;
 }

# Sample mapping for removing Line Feeds from streetaddress attribute:
# streetaddress#1024=& remove_lf("^streetaddress^") &


####################################################
# Subroutine to remove non digit characters from telephone number

sub onlydigits
 {
   my $temp=$_[0];
   $temp=~s/\D//g;
   return $temp;
 }

# Sample mapping for removing non digit characters from telephonenumber:
# telephonenumber#64=& onlydigits("^telephonenumber^") &


######################################################
# Subroutine to convert international characters

sub convert
 {
   my $temp=utf8($_[0])->latin1;
   $temp=~s/ô/o/g;
   $temp=~s/è/e/g;
   $temp=~s/é/e/g;
   $temp=~s/à/a/g;
   $temp=~s/û/i/g;
   $temp=~s/û/u/g;
   $temp=~s/ç/e/g;
   $temp=~s/ê/e/g;
   $temp=~s/ü/ue/g;   
   return $temp;
 }

# Sample mapping for converting international characters:
# displayname#256=& $_=convert("~cn~"); &

# Sample mapping for converting international characters AND removing line feeds:
# streetaddress#1024=& $_=convert(remove_lf("^postaladdress^")); &

# #######################################################
# Subroutine to remove forward slash / character

sub remove_fslash
 {
   my $temp=$_[0];
   $temp=~s/\///g;
   return $temp;
 }

# #######################################################
# Subroutine to truncate at first { character.

sub truncit
{

    my $temp=$_[0];
     if ($temp =~ /^(.*?)\{/)
          {
             return $1;
          }
}

# Sample mapping:
# description=& truncit("^description^") &

 

# #######################################################
# Subroutine to truncate at first instance of "OU="

 

sub trimdn
{
   my $dn=$_[0];
      if ($dn=~/^(.*?)OU=/)
         {
             my $cnt = @{[$1 =~ /./sg]};
             my $value = substr($dn, $cnt);
             return $value;
          }
}

 

#Sample mapping:
#container=&trimdn("^distinguishedName^")&