Programmatic Workflow Submission
I have a pagecontrol that can be used to create Events. I also created a 1 step workflow for Event approval. When I create Events through the Sitefinity backend, the Events are submitted to the workflow correctly. However, when the Events are created using the pagecontrol on the frontend, the new Event bypasses the workflow. I couldn't find any documentation on how to programmatically submit the new Event to the workflow. How would I accomplish this?
Thanks.
Hello Geoff,
The Event object and PageNode have property - ApprovalWorkflowState which you can set to
Thanks. I set the ApprovalWorkflowState to "AwaitingApproval" using the SetString method. This brings up two new issues.
First, I'm trying to display these events in a RadScheduler so they show up in a calendar view. I am filtering the events based on their Category taxon and their Status == ContentLifecycleStatus.Live. When an event is created, it looks like two copies are created when I retrieve them from Events. The first has ContentState == null, Status == ContentLifecycleStatus.Live and the second one has ContentState == PUBLISHED, Status == ContentLifecycleStatus.Master. I'm assuming I will need to filter by ContentState == PUBLISHED in addition to Status == ContentLifecycleStatus.Live to get the proper active events to display on the calendar. Is this a correct assumption?
Second, when an event is created programmatically, a user from the approving role is not able to approve the event. However, when an event is created from the Sitefinity backend, the same user is able to approve the event just fine. Is there another property that needs to be set besides ApprovalWorkflowState to make sure the event moves into the property workflow?
Thanks.
Here are what I thought were the relevant properties of the Event objects. Let me know if I should pay attention to any other properties.
Created programmatically:
2 Event objects
ContentState: null
Status: Live
Title: Event 01
ApprovalWorkflowState: AwaitingApproval
ContentState: PUBLISHED
Status: Master
Title: Event 01
ApprovalWorkflowState: AwaitingApproval
Created through Sitefinity backend:
1 Event object
ContentState: null
Status: Master
Title: Event 02
ApprovalWorkflowState: AwaitingApproval
When I create an Event programmatically, why does it create a Master and a Live version, but when I create an Event through the Sitefinity backend, only a Master version is created?
Also, the ContentState of the Master version when created programmatically is set to PUBLISHED, while the ContentState of the Master version created through the Sitefinity backend is set to null. What is causing this variance?
Here is my code for creating the Events:
App.WorkWith().Event().CreateNew().Do(calEvent =>
calEvent.ApprovalWorkflowState =
"AwaitingApproval"
;
// set info properties of the event (title, eventstart, etc..)
).Publish().SaveChanges();
Ivan, do you have any additional insight into this issue? Let me know if I can provide any additional information to help reach a solution.
Thanks.
Hi,
I take a look to this post. In your code example you use Publish method so ContentState of the master is set to PUBLISHED ;).
If it's same as Page ensure Title are correctly initialized for Draft and Data.
Regards
Nicolas
Thank you, that was my mistake. Now the Event is set to "Awaiting Approval" in the Sitefinity backend, but users of the role set to approve Events are unable to approve them. Instead of an "Approve" button, they have a "Send for Approval" button like the users of the other roles. Do I need to set a property on Event creation so it knows which workflow to enter?
Thanks.
Just to wrap up this thread in case someone else has this issue.
App.WorkWith().Event().CreateNew().Do(calEvent =>
// calEvent.ApprovalWorkflowState = "AwaitingApproval";
// Setting this property when creating an event was breaking my workflow entry.
// set info properties of the event (title, eventstart, etc..)
).Publish().SaveChanges();