Import data and publish?
Is there a way to import data into my module built with the module builder and have it come in published?
Here's a snippet of my code that executes for each item.
DynamicModuleManager dynamicModuleManager = DynamicModuleManager.GetManager();
Type communityResourceType = TypeResolutionService.ResolveType(
"Telerik.Sitefinity.DynamicTypes.Model.CommunityResources.CommunityResource"
);
DynamicContent communityResourceItem = dynamicModuleManager.CreateDataItem(communityResourceType);
// code that sets values for each item
dynamicModuleManager.SaveChanges();
Hi Julia,
You need to add a few more lines of code to your method in order to publish your items programatically: Here they are:
//This is the additional line that needs to be executed
// set the workflow UI status
InitializeApprovalTrackingRecordMap((IApprovalWorkflowItem)communityResourceType, dynamicModuleManager.Provider.ApplicationName,
"Published"
);
// We can now call the following to publish the item
dynamicModuleManager.Lifecycle.Publish(communityResourceType);
// You need to call SaveChanges() in order for the items to be actually persisted to data store
dynamicModuleManager.SaveChanges();
public
static
void
InitializeApprovalTrackingRecordMap(IApprovalWorkflowItem workflowItem,
string
applicationName,
string
status =
"Published"
)
if
(workflowItem.ApprovalTrackingRecordMap ==
null
)
var approvalTrackingMap =
new
ApprovalTrackingRecordMap() Id = Guid.NewGuid() ;
workflowItem.ApprovalTrackingRecordMap = approvalTrackingMap;
var trackingRecord =
new
ApprovalTrackingRecord()
ApplicationName = applicationName,
Culture = CultureInfo.InvariantCulture.LCID,
DateCreated = DateTime.Now,
Id = Guid.NewGuid(),
LastModified = DateTime.Now,
Note =
string
.Empty,
Status = status,
UserId = SecurityManager.CurrentUserId,
WorkflowItemId = workflowItem.Id
;
workflowItem.ApprovalTrackingRecordMap.ApprovalRecords.Add(trackingRecord);
workflowItem.ApprovalWorkflowState.SetString(CultureInfo.InvariantCulture, status);
using
System;
using
System.Globalization;
using
Telerik.Sitefinity;
using
Telerik.Sitefinity.Model;
using
Telerik.Sitefinity.Web.UI.Fields;
using
Telerik.Sitefinity.DynamicModules;
using
Telerik.Sitefinity.DynamicModules.Model;
using
Telerik.Sitefinity.Utilities.TypeConverters;
using
Telerik.Sitefinity.Workflow.Model.Tracking;
using
Telerik.Sitefinity.Security;
Thanks. That worked, but with a couple of corrections (shown below). Where you referred to the communityResourceType, it needed to be the communityResourceItem.
//This is the additional line that needs to be executed
// set the workflow UI status
InitializeApprovalTrackingRecordMap((IApprovalWorkflowItem)communityResourceItem, dynamicModuleManager.Provider.ApplicationName,
"Published"
);
// We can now call the following to publish the item
dynamicModuleManager.Lifecycle.Publish(communityResourceItem);
// You need to call SaveChanges() in order for the items to be actually persisted to data store
dynamicModuleManager.SaveChanges();
Hi Julia,
You are absolutely right. I am sorry for misleading you.
Regards,
Lilia Messechkova
the Telerik team