January 9, 2017 Development Tips

Kentico Custom Module Development - Ensuring Child Objects Synch With Parent Staging Tasks

By: Laura Frese
I recently worked on a project in Kentico 10 that required some custom module development. Some of the classes in the custom module had parent child relationships that needed to be set up programmatically. Since I needed to log tasks for the custom module objects in staging, I needed to ensure that the child objects would synchronize with the parent when the parent was synchronized instead of creating individual tasks for each of the child objects as they were inserted or updated. Unfortunately, the instructions on how to accomplish this were not clear in the documentation. In this post I will show you how to programmatically modify the child classes so that they will synchronize with the parent. 

Parent Info.cs file Type Information section

public static ObjectTypeInfo TYPEINFO = new ObjectTypeInfo(typeof(CompanyInfoProvider), OBJECT_TYPE, 
"CompanyOverview.Company", "CompanyID", "CompanyLastModified", "CompanyGUID", "CompanyName", 
"CompanyDisplayName", null, null, null, null)
{
    ModuleName = "CompanyOverview",
    TouchCacheDependencies = true,   
    SynchronizationSettings =
    {
        LogSynchronization = SynchronizationTypeEnum.LogSynchronization, // Enables logging of staging tasks for changes made to Office objects
        ObjectTreeLocations = new List()
        {
            // Creates a new category in the 'Global objects' section of the staging object tree
            new ObjectTreeLocation(GLOBAL, "CompanyOverview")
        }
    }
};
Child Info.cs Type Information section:

public static ObjectTypeInfo TYPEINFO = new ObjectTypeInfo(typeof(OfficeInfoProvider), OBJECT_TYPE, 
"CompanyOverview.Office", "OfficeID", "OfficeLastModified", "OfficeGUID", "OfficeName", "OfficeDisplayName", 
null, null, null, null)
{
    ParentIDColumn = "CompanyID",
    ParentObjectType = CompanyInfo.OBJECT_TYPE,
    ModuleName = "CompanyOverview", 
    SynchronizationSettings =
    {
        LogSynchronization = SynchronizationTypeEnum.TouchParent, 
        IncludeToSynchronizationParentDataSet = IncludeToParentEnum.Complete,
        
    }
};
Share: