More in this section
Forums / Developing with Sitefinity / Sitefinity CreateDataItem for Child Content Type results in Live and Visible record with Null for system_parent_id

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

The forums are in read-only mode. In case that you want to directly contact the Progress Sitefinity team use the support center. In our Google Plus group you can find more than one thousand Sitefinity developers discussing different topics. For the Stack Overflow threads don’t forget to use the “Sitefinity” tag.
2 posts, 1 answered
  1. Jacques
    Jacques avatar
    427 posts
    Registered:
    28 Jun 2007
    24 Aug 2017
    Link to this post

    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?

  2. Jacques
    Jacques avatar
    427 posts
    Registered:
    28 Jun 2007
    24 Aug 2017 in reply to Jacques
    Link to this post

    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();
    Answered
2 posts, 1 answered