Skip to main content

Sitecore 9 Dynamic CRM Connector: Custom pipeline to filter contacts (Part 4)

Sitecore 9 Dynamic CRM Connector: Custom pipeline to filter contacts (Part 4)

Part 3Sitecore 9 Dynamic CRM Connector: Sync Known contacts (Part 3)

As per my requirement, I had multiple Sitecore 9 Forms, in each form I am saving contacts in xDB but I want to sync contacts to CRM which is submitted by a specific form.To fulfil this requirement, I have created custom model & facet and according to custom facets, I have applied logic that only those contact will be sync which contact has the custom model. Also, I have created a pipeline to get the required properties.

Step 1: Create custom pipeline template

  •        Navigate to this location “/sitecore/templates/Data Exchange/Framework/Pipeline Steps” and create new template
o   Template :/sitecore/templates/Data Exchange/Framework/Pipeline Steps/Base Pipeline Steps/Base Pipeline Step
o   Item Name: Custom Filter Pipeline Step
  •      Add IterableDataLocation field:
o   Name: IterableDataLocation
o   Type: DropLink
o   ID: {DD61BBDB-CF41-40F6-9923-3031C7AB47C8}
o   Shared: true
  •       Add DataLocation field:
o   Name: DataLocation
o   Type: DropLink
o   ID: {DD61BBDB-CF41-40F6-9923-3031C7AB47C8}
                     o   Shared: true
  •       Add ContactFacetsToRead field:
o   Name: ContactFacetsToRead
o   Type: DropTree
o   ID: {D6E7B01E-9E17-4237-AEE9-05EBFD1DF9D2}
o   Shared: true


  •  In standard value select below default values:

Step 2: Create custom plugin

  •      Navigate to Visual studio and create custom class “ReadFacetSettings”
 using Sitecore.DataExchange;  
 namespace Namespace.Plugins  
 {  
 public class ReadFacetSettings : IPlugin  
   {  
     public string FacetNames  
     {  
       get;  
       set;  
     }  
   }  
 }  

Step 3: Create custom processor “CustomFilterPipelineStepConverter”


 using Sitecore.DataExchange.Attributes;  
 using Sitecore.DataExchange.Converters.PipelineSteps;  
 using Sitecore.DataExchange.Models;  
 using Sitecore.DataExchange.Plugins;  
 using Sitecore.DataExchange.Repositories;  
 using Sitecore.Foundation.Forms.Custom.Pipelines.Plugins;  
 using Sitecore.Services.Core.Model;  
 using System;  
 using System.Collections.Generic;  
 namespace Namespace.Converters  
 {  
   [SupportedIds(new string[]  
    {  
     "TemplateID"  
    })]  
   public class CustomFilterPipelineStepConverter : BasePipelineStepConverter  
   {  
     public CustomFilterPipelineStepConverter(IItemModelRepository repository) : base(repository)  
     {  
     }  
     protected override void AddPlugins(ItemModel source, PipelineStep pipelineStep)  
     {  
       this.AddDataLocationSettingsPlugin(source, pipelineStep);  
       this.AddReadEntitySettings(source, pipelineStep);  
     }  
     private void AddDataLocationSettingsPlugin(ItemModel source, PipelineStep pipelineStep)  
     {  
       Guid guidValue = base.GetGuidValue(source, "DataLocation");  
       Guid guidValue2 = base.GetGuidValue(source, "IterableDataLocation");  
       pipelineStep.AddPlugin<IterateDataSettings>(new IterateDataSettings  
       {  
         DataLocation = guidValue,  
         IterableDataLocation = guidValue2  
       });  
     }  
     protected virtual void AddReadEntitySettings(ItemModel source, PipelineStep pipelineStep)  
     {  
       ReadFacetSettings readEntitySettings = new ReadFacetSettings();  
       IEnumerable<ItemModel> referencesAsModels = base.GetReferencesAsModels(source, "ContactFacetsToRead");  
       if (referencesAsModels != null)  
       {  
         foreach (ItemModel current in referencesAsModels)  
         {  
           string stringValue = base.GetStringValue(current, "FacetName");  
           readEntitySettings.FacetNames = stringValue;  
         }  
       }  
       pipelineStep.AddPlugin<ReadFacetSettings>(readEntitySettings);  
     }  
   }  
 }  

Step 4: Create custom processor “CustomFilterPipelineStepProcessor”

 using Sitecore.DataExchange.Attributes;  
 using Sitecore.DataExchange.Contexts;  
 using Sitecore.DataExchange.Models;  
 using Sitecore.DataExchange.Plugins;  
 using Sitecore.DataExchange.Processors.PipelineSteps;  
 using Sitecore.DataExchange.Providers.XConnect.Models;  
 using Sitecore.Foundation.Forms.Custom.Pipelines.Plugins;  
 using Sitecore.Services.Core.Diagnostics;  
 using System;  
 using System.Collections;  
 using System.Collections.Generic;  
 using System.Linq;  
 namespace Namespace.Processors  
 {  
   [RequiredPipelineStepPlugins(new Type[]  
    {  
     typeof(PipelinesSettings),  
     typeof(IterateDataSettings)  
    })]  
   public class CustomFilterPipelineStepProcessor : BasePipelineStepProcessor  
   {  
     protected override bool CanStartProcessing(PipelineStep pipelineStep, PipelineContext pipelineContext, ILogger logger)  
     {  
       if (pipelineStep.GetPlugin<IterateDataSettings>().DataLocation == Guid.Empty)  
       {  
         this.Log(new Action<string>(logger.Error), pipelineContext, "No data location is specified.", Array.Empty<string>());  
         return false;  
       }  
       return true;  
     }  
     protected override void ProcessPipelineStep(PipelineStep pipelineStep, PipelineContext pipelineContext, ILogger logger)  
     {  
       IEnumerable iterableData = this.GetIterableData(pipelineStep, pipelineContext, logger);  
       if (iterableData == null)  
       {  
         this.Log(new Action<string>(logger.Debug), pipelineContext, "Iterable data is null.", Array.Empty<string>());  
         return;  
       }  
       ReadFacetSettings facetPlugin = pipelineStep.GetPlugin<ReadFacetSettings>();  
       if (facetPlugin == null || facetPlugin.FacetNames==null)  
       {  
         this.Log(new Action<string>(logger.Debug), pipelineContext, "Contact Facets To Read is null.", Array.Empty<string>());  
         return;  
       }  
       List<EntityModel> list = iterableData.Cast<EntityModel>().ToList();  
       List<EntityModel> filterList = new List<EntityModel>();  
       foreach (var data in list)  
       {  
         if (data.Facets.Keys.Any(x => x == facetPlugin.FacetNames))  
         {  
           filterList.Add(data);  
         }  
       }  
       IterableDataSettings newPlugin = new IterableDataSettings(filterList);  
       pipelineContext.AddPlugin<IterableDataSettings>(newPlugin);  
     }  
     protected virtual IEnumerable GetIterableData(PipelineStep pipelineStep, PipelineContext pipelineContext, ILogger logger)  
     {  
       IterateDataSettings plugin = pipelineStep.GetPlugin<IterateDataSettings>();  
       return this.GetObjectFromPipelineContext(plugin.IterableDataLocation, pipelineContext, logger) as IEnumerable;  
     }  
   }  
 }  

Step 5: Create custom pipeline

  •      Add the following item.
o   Template: /sitecore/system/Data Exchange/XXX/Pipelines/xConnect Contacts to Dynamics Sync Pipelines/Read Contacts from xConnect Pipeline/Custom Filter Pipeline Step
o   Item Name: Custom Filter Pipeline Step

  •       Navigate to “ContactFacetsToRead” field and select custom facet]
  •       Update Converter Type and Processor Type field

Step 6: Run Batch

  •       Now run “xConnect Contacts to Dynamics Sync” batch
Next article will be about "Scheduled Pipeline Batches"

Comments

Popular posts from this blog

Sitecore 10.2 - “Failed to start service ‘Sitecore Marketing Automation Engine’” on Windows 11

Sitecore 10.2 - “Failed to start service ‘Sitecore Marketing Automation Engine' ” on Windows 11 Today I started to install Sitecore 10.2 using Sitecore Instance Manager on Windows 11 and I got this issue “Failed to start service ‘Sitecore Marketing Automation Engine' ” . Error : On event viewer it was showing the below error: I also tried to run ‘ Sitecore.MAEngine.exe ’ like this C:\Windows\system32>C:\inetpub\wwwroot\sclocal102xconnect.dev.local\App_Data\jobs\continuous\AutomationEngine\Sitecore.MAEngine.exe Which was throwing below error: Starting Marketing Automation Engine... 2022-01-29 22:21:11 ERR Error initializing XConnect client. System.AggregateException: One or more errors occurred. ---> Sitecore.XConnect.XdbCollectionUnavailableException: An error occurred while sending the request. ---> System.Net.Http.HttpRequestException: An error occurred while sending the request. ---> System.Net.WebException: The underlying connection was closed: An unexpected err...

Azure AD Integration with Sitecore 10.2

 Azure AD Integration with Sitecore 10.2 Sitecore identity server that comes with Sitecore 9.1 allows you to log in through an external identity provider like Azure Active Directory, Facebook, Apple, or Google. It is built on Federation Authentication. What is Federation Authentication? Federation authentication is a technology to allows users to access multiples application, tools, and domains using one credential. Using one set of credential user can access multiple applications, and resources after authentication.  Federation authentication consists of two systems, the Identity provider and the Service provider. Identity providers that maintain/create/manage identity information like name, email address, device, and location. Some examples of identity providers are Azure AD, Google, Facebook, and Apple. Service providers basically refer to a website, software, or app that the user is trying to access and SP basically relies on the identity provider to authenticate the user ...

Sitecore 9 Forms: Google reCaptcha field

Sitecore 9 Forms: Google reCaptcha field  Re-Captcha is the most important part of any form’s submission. Google reCaptcha run internet bot detector and determined whether a user is a bot or not.  Sitecore Forms does not provide Google reCaptcha field, which was available in WFFM before, so I have created my custom Google reCaptcha.   Below you can find step by step process to create Google reCaptcha field. Create patch config for reCaptcha Sitekey and SecretKey <?xml version="1.0"?> <configuration xmlns:patch="http://www.sitecore.net/xmlconfig/" xmlns:set="http://www.sitecore.net/xmlconfig/set/"> <sitecore> <settings> <setting name="ReCaptchaSiteKey" value="site-key" /> <setting name="ReCaptchaSecretKey" value="secret-key" /> </settings> </sitecore> </configuration> Create new viewmodel class RecaptchaViewMode...