2017-08-24 30 views
0

我非常渴望得到這個答案。我正在使用Sitefinity API爲父項目創建子項目。 (這些是一個動態模塊中的動態內容的類型)在API中創建帶有API結果的動態內容記錄system_parent_id = null

在設置屬性的端部i執行以下操作:

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

結果是兩個記錄在sf_dynamic_content表,它是正確的,但是第二記錄出於某種原因,即使它的值爲可見= 1和狀態= 2,system_parent_id也爲null。

這就好像我在過程中丟失了某些東西,因爲當Live記錄被創建時,它不會複製parent_id即使主記錄正確引用了家長ID。

如果我進入管理界面,打開我創建的記錄並單擊發布,那麼它會正確複製父ID,但API方法不會這樣做。爲什麼?

回答

1

在調用「發佈」之前以及設置工作流程狀態之前,您一定要設置父級。

這裏是一個示例代碼:

var parentMasterId = Id_of_the_parent_item; 

// type is the full name of the dynamic module 
string resolvedType = TypeResolutionService.ResolveType(type); 

// create the child item 
var itemToCreate = manager.CreateDataItem(resolvedType); 

// set some other properties of the child, like Title, etc. 

// set the parent of the child 
itemToCreate.SetParent(parentMasterId, "full_name_of_the_parent_type"); 

itemToCreate.SetWorkflowStatus(manager.Provider.ApplicationName, "Published"); 

manager.Lifecycle.Publish(itemToCreate); 

manager.SaveChanges(); 
+0

偉業我這就是答案。我在得到你的答覆之前就已經明白了。奇怪的是,在模塊生成器提供的代碼引用中,它反其道而行之。 – Jacques