API Workflow Entry Point

Posted by Community Admin on 05-Aug-2018 20:04

API Workflow Entry Point

All Replies

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

I created a workflow for event approval before they are published. When I create events using the fluent API, they say they are awaiting approval in the Sitefinity backend, but the role assigned to approve the events has a "Send For Approval" button instead of an "Approve" button.  Is there a property that needs to be set to specify which workflow the new event will enter into?

Here is my current code:

App.WorkWith().Event().CreateNew().Do(calEvent =>
    
        calEvent.ApprovalWorkflowState = "AwaitingApproval";
 
        // Set event properties
        calEvent.Title = txtEventName.Text;
        // etc...
    )
    .SaveChanges();

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

Hi Geoff,
The problem is that you should notify workflow that the item is moved from one state to another. Here is the code to do that:

var evntId = Guid.Empty;
App.WorkWith().Event().CreateNew().Do(e =>
       
        e.Title = "evv1";
        evntId = e.Id;
       ).SaveChanges();
var eventItem = App.WorkWith().Event(evntId).Get();
var masterId = eventItem.OriginalContentId;
EventsManager.GetManager().RecompileItemUrls<Event>(eventItem);
if (eventItem.Status == ContentLifecycleStatus.Master)
            
                EventsManager.GetManager().CheckOut(eventItem);
                masterId = eventItem.Id;
            
  
EventsManager.GetManager().SaveChanges();
  
var contextBag = new Dictionary<string, string>();
contextBag.Add("ContentType", eventItem.GetType().FullName);
  
WorkflowManager.MessageWorkflow(
             masterId,
             eventItem.GetType(),
             EventsManager.GetDefaultProviderName(),
             "SendForApproval",
             false,
             contextBag);

With this code, you create event item and send message to workflow that you are sending this item for approval.

Greetings,
Bonny Bonev
the Telerik team

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

This is what I was looking to do, but unfortunately it doesn't appear to be working.  With this code, I am still having the same issue. The event is created and shows up under events as "awaiting approval", but the users under the role that is qualified to approve the events is unable to approve them.  They can only "Send For Approval".

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

Also, using the posted code, the event now shows up as checked out and if I try to call

EventsManager.GetManager().CheckIn(eventItem);
I get the error "Cannot check in item that is not in temp state".

How do I get the role set to approve events able to approve the created events?
How do I get the event checked in upon the posted code executing?

Thanks.

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

Hello Geoff,

I just tried again this code and it worked fine. Are you running the code using a user that is qualified to approve the events? If you are doing this from an admin account, this will probably not work if administrators are allowed to skip this step (Send for approval) because it will not be a valid workflow operation. Try to run this code from a user account with permissions "send for approval" and  "approve".

Regards,
Bonny Bonev
the Telerik team

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

Thank you for pointing that out.  Your posted code does work as expected if not using an Admin account.  Thank you very much, Bonny.

As a side note, on the workflow settings, "Allow administrators to skip the workflow" is unchecked.  Should this still prevent an administrator user from created events and entering them into the workflow as described in my last post?

Thanks.

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

Hello Geoff,

Allow administrators to skip the workflow - when true, a user that belongs to Administrators role skip the steps you have defined for your workflow.

All the best,
Ivan Dimitrov
the Telerik team

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

Yes, but can you reproduce the issue described in my last post?  When creating events and submitting them to a workflow programmatically.  I was bringing this up in case it was a reproducible bug that needed to be noted or resolved on your end.

Thanks.

Posted by Community Admin on 01-Apr-2011 00:00

Hi Geoff,

I tried this, but I still can't reproduce your problem. I guess that the issue is fixed. You can try this with Q1 and I hope that you will not experience this problem again.

Regards,
Bonny Bonev
the Telerik team

This thread is closed