Sitecore 9 Dynamic CRM Connector: Conditionally Sync Sitecore Field (Part 6)
Part 5: Schedule Pipeline Batches in Sitecore 9 Dynamic CRM Connector
There can be the situation while you are syncing xDB contacts to CRM and you want to update some field on the basis of some logic. Just like the below condition where I wanted to sync to “Birthdate” when it is above 1990 otherwise, it will be blank in CRM.
There can be the situation while you are syncing xDB contacts to CRM and you want to update some field on the basis of some logic. Just like the below condition where I wanted to sync to “Birthdate” when it is above 1990 otherwise, it will be blank in CRM.
Apply Mapping Rules
- To apply mapping rules firstly create custom class “BirthdateValueMappingRule”
namespace Namespace
{
public class BirthdateValueMappingRule : IApplyMappingRule
{
public readonly int Year = 1990;
public readonly string FacetName = "Personal";
public bool ShouldMappingBeApplied(object value, IMapping mapping, MappingContext context)
{
if (value != null && context != null)
{
var MappingSource = (EntityModel)context.Source;
var MappingFacets = MappingSource?.Facets;
if (MappingFacets != null)
{
foreach (var facet in MappingFacets)
{
if (facet.Key.Equals(FacetName))
{
var val = (PersonalInformation)facet.Value;
if (val.Birthdate != null)
{
DateTime date = (DateTime)val.Birthdate;
if (date.Year > Year)
{
return true;
}
else
{
return false;
}
}
else
{
return true;
}
}
}
}
}
return true;
}
}
}
- Create another class “BirthdateValueMappingRuleConvertor”
namespace Namespace
{
public class BirthdateValueMappingRuleConvertor : BaseItemModelConverter<IApplyMappingRule>
{
private static BirthdateValueMappingRule _rule;
public BirthdateValueMappingRuleConvertor(IItemModelRepository repository)
: base(repository)
{
}
protected override ConvertResult<IApplyMappingRule> ConvertSupportedItem(
ItemModel source)
{
if (_rule == null)
_rule = new BirthdateValueMappingRule();
return PositiveResult(_rule);
}
}
}
- In Sitecore, navigate to this location “/sitecore/system/Data Exchange/XXX/Data Access/Apply Mapping Rules/Providers” and create “xConnect Apply Mapping Rules” item
- Create an item
- Template: /sitecore/templates/Data Exchange/Framework/Data Access/Apply Mapping Rules/Null Value Mapping Rule
- Item Name: “Birthdate Mapping Rule”
- Update “Converter Type” field with “Namespace.BirthdateValueMappingRuleConvertor,AssemblyName”
Comments