What we want to do is to map the Outlook Field Category to the Custom CRM field Type
We assume that custom field is called cat_type_c (name of database column). If not, it should be renamed below accordingly. The example below is for Contacts module. Of course, field name and module may be changed.
Go to the folder: c:\ProgramData\GrinMark\AESync\Templates\syncdefs. Open file ExchangeConversionInfo.xml in the text editor:
Find section with rules for Contacts module:
<ConversionRules ForModule="Contacts" ToModule="Contacts" Description="Exchange2Sugar" Action="SynchContactsE2S">
Add new FieldRule to it:
<FieldRule Name="!set_type_by_category">
<rule xsi:type="ExprRule">
<ScriptText>
<![CDATA[
var categories = src["_Item"].Categories;
// The cat_type_c field should be defined in Sugar.xml for the Contacts module
if(categories.Contains("CRM"))
{
SyncUtils.Log("Category detected: CRM");
dst["cat_type_c"] = "CRM";
}
if(categories.Contains("MyValue"))
{
SyncUtils.Log("Category detected: MyValue");
dst["cat_type_c"] = "MyValue";
}
return "success";
]]>
</ScriptText>
</rule>
</FieldRule>
Synchronizer should be told that there is a field cat_type_c in the module Contacts. This field should be defined in the Sugar.xml like that:
<ModuleInfo name="Contacts" adapterType="SugarSoapCommon.SugarAdapter" localizedName="Contacts">
<Fields>
...
<Text name="cat_type_c" localizedName="cat_type_c" displayOnly="false" />
...
</Fields>
</ModuleInfo>
Re-start the service for the new settings to take effect.
In this example we customized the behavior of synchronizer. In this example we changed the rule for only one direction: Exchange->SugarCRM. The same approach may be used to add logic for opposite direction.
If anything goes wrong, please refer the log files stored in the c:\ProgramData\GrinMark\AESync\Date\[Profile Name]\agent.log
Please note: It is recommended to tweak the synchronizer with single user and test data before expanding it to multiple users.
This example demonstrated synchronization of categories from Exchange to Sugar. Backward synchronization is also possible.
Sometimes it is required to set a category based on the data in the CRM.
Go to the folder: c:\ProgramData\GrinMark\AESync\Templates\syncdefs. Open file "ExchangeConversionInfo.xml" in the text editor:
Find section with rules for Contacts module:
<ConversionRules ForModule="Contacts" ToModule="Contacts" Description="Sugar2Exchange" Action="SynchContactsS2E">
Add new FieldRule to it:
<FieldRule Name="!Set_type_by_category">
<rule xsi:type="ExprRule">
<ScriptText>
<![CDATA[
var categories = dst["_Item"].Categories;
// The cat_type_c field should be defined in Sugar.xml for the Contacts module
var cat = ""+src["cat_type_c"];
if(!categories.Contains(cat))
{
SyncUtils.Log("Assigning category: "+cat);
categories.Add(cat);
dst["_Item"].Update(2/*ConflictResolutionMode.AlwaysOverwrite*/);
}
return "success";
]]>
</ScriptText>
</rule>
</FieldRule>
If CRM category field contains comma or semicolon separated list of categories then FieldRule should be a bit more complex:
<FieldRule Name="!Set_type_by_category" requiresId="true">
<rule xsi:type="ExprRule">
<ScriptText>
<![CDATA[
var categories = dst["_Item"].Categories;
// The cat_type_c field should be defined in Sugar.xml for the Contacts module
var crmCategories:String = "" + src["cat_type_c"];
SyncUtils.Log("CRM Categories: " + crmCategories);
var cats:String[] = crmCategories.Split([',', ';']);
var newCategoriesAdded:Boolean = false;
for (var i:Number in cats)
{
var cat:String = cats[i].Trim();
if(!categories.Contains(cat))
{
SyncUtils.Log("Assigning category: " + cat);
categories.Add(cat);
newCategoriesAdded = true;
}
}
if (newCategoriesAdded)
{
dst["_Item"].Update(2/*ConflictResolutionMode.AlwaysOverwrite*/);
}
return "success";
]]>
</ScriptText>
</rule>
</FieldRule>