The need is to integrate Kentico 12 XP with an external PIM system. I would like to be able to process the information received by the PIM in a scheduled job, in order to create or update elements in Kentico. I tried to implement a POC, using the native Integration Bus and creating a custom scheduled task in Kentico. From what I understand from the documentation, you can get into the bus integration pipeline by extending the BaseIntegrationConnector base class and overwriting the PrepareInternalObject method:
public override ICMSObject PrepareInternalObject(object obj
,TaskTypeEnum taskType
,TaskDataTypeEnum dataType
,string siteName)
{
var pimObj = (dynamic)obj;
var node = new Product
{
DocumentName = pimObj.Name,
DocumentCulture = "en-us",
Name = pimObj.Name,
Family = pimObj.Family,
NodeParentID = 2
};
return node;
}
As a first step, I implemented a connector and overridden the above method, so that it can create a new Product instance after reading data from the PIM through its APIs.
As a last step I created a custom task as follows:
public class CustomSyncTask : CMS.Scheduler.ITask
{
public string Execute(TaskInfo task)
{
// Call PIM and build pimObject ...
try
{
IntegrationHelper.ProcessExternalTask("CustomIntegrationConnector"
,pimObject
,IntegrationProcessTypeEnum.SkipOnError
,TaskTypeEnum.CreateDocument
,TaskDataTypeEnum.Simple
,SiteContext.CurrentSite.SiteName);
}
catch (Exception ex) {
return ex.Message;
}
}
return null;
}
I did not expect any particular errors, since the implementation is really simple, unfortunately, running the task I always get the same error:
Message: Object reference not set to an instance of an object.
Exception type: System.NullReferenceException
Stack trace:
at CMS.DataEngine.TranslationHelper.RegisterRecord(BaseInfo infoObject)
at CMS.DocumentEngine.DocumentSynchronizationHelper.GetDocumentDataSet(TreeNode node, TranslationHelper th, TaskTypeEnum taskType, TaskDataTypeEnum dataType, TaskParameters taskParams, String siteName)
at CMS.DocumentEngine.DocumentSynchronizationHelper.GetDocumentXML(TreeNode node, TranslationHelper th, TreeProvider tree, TaskTypeEnum taskType, TaskDataTypeEnum dataType, TaskParameters taskParams, String siteName)
at CMS.DocumentEngine.DocumentSynchronizationHelper.LogExternalIntegration(TreeNode node, TreeProvider tree, TaskTypeEnum taskType, TaskDataTypeEnum dataType, IntegrationProcessTypeEnum result, String connectorName, TranslationHelper th, String siteName)
I deeply investigated in the Kentico source code and found that, when trying to call the RegisterRecord, the Site property ( null ) is passed as parameter. The Site property is set when the Product item is created in Kentico. Hence the contradiction: how is it possible that the object should already be created if the intention is to create it? Am I doing something wrong? Did I misinterpre the entire process?