Programmatic Workflow Submission

Posted by Community Admin on 05-Aug-2018 00:19

Programmatic Workflow Submission

All Replies

Posted by Community Admin on 09-Mar-2011 00:00

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.

Posted by Community Admin on 09-Mar-2011 00:00

Hello Geoff,

The Event object and PageNode have property - ApprovalWorkflowState which you can set to

  • Published
  • Draft
  • Scheduled
  • AwaitingApproval

All the best,
Ivan Dimitrov
the Telerik team
Registration for Q1 2011 What’s New Webinar Week is now open. Mark your calendar for the week starting March 21st and book your seat for a walk through all the exciting stuff we ship with the new release!

Posted by Community Admin on 09-Mar-2011 00:00

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.

Posted by Community Admin on 11-Mar-2011 00:00

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();

What other properties should I be setting or changes should I make to make the created Event consistent with the Event created through the Sitefinity backend?

Thanks.

Posted by Community Admin on 15-Mar-2011 00:00

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.

Posted by Community Admin on 16-Mar-2011 00:00

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

Posted by Community Admin on 16-Mar-2011 00:00

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.

Posted by Community Admin on 24-Mar-2011 00:00

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();


The solution is documented in this thread.

Thanks.

This thread is closed