Sitefinity CreateDataItem for Child Content Type results in

Posted by Community Admin on 04-Aug-2018 08:46

Sitefinity CreateDataItem for Child Content Type results in Live and Visible record with Null for system_parent_id

All Replies

Posted by Community Admin on 24-Aug-2017 00:00

I'm desperate for an answer to this. I'm using the Sitefinity API to create Child Items for a Parent Item. (These are dynamic content types in a dynamic module)
At the end of setting the properties I do the following:

historicDataEntry.SetWorkflowStatus(dynamicModuleManager.Provider.ApplicationName, "Published"); dynamicModuleManager.Lifecycle.Publish(historicDataEntry); historicDataEntry.SetParent(GetFundIDToUse(), etfType.FullName); dynamicModuleManager.SaveChanges();

The result is two records in the sf_dynamic_content table which is right, but the second record for some reason has a system_parent_id of null even though it gets the values visible = 1 and status = 2.

It's as though I'm missing something in the process because when the Live record is created it's not copying the parent_id even though the Master record correctly references the Parent ID.

If I go into the admin interface, open the record I created and click publish THEN it copies the parent ID correctly, but the API approach doesn't do that. Why?

Posted by Community Admin on 24-Aug-2017 00:00

Turns out the Code Reference provided by the Module Builder seem to be incorrect. Setting the Parent first and then the Workflow and Publishing solves the problem: 

historicDataEntry.SetParent(GetFundIDToUse(), etfType.FullName);
historicDataEntry.SetWorkflowStatus(dynamicModuleManager.Provider.ApplicationName, "Published");
dynamicModuleManager.Lifecycle.Publish(historicDataEntry);
dynamicModuleManager.SaveChanges();

This thread is closed