+1-888-365-2779
Try Now
More in this section

Forums / Sitefinity SDK / API Workflow Entry Point

API Workflow Entry Point

9 posts, 2 answered
  1. Geoff
    Geoff avatar
    89 posts
    Registered:
    02 Mar 2011
    22 Mar 2011
    Link to this post
    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();
  2. Bonny
    Bonny avatar
    58 posts
    Registered:
    11 Nov 2016
    24 Mar 2011
    Link to this post
    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
    Answered
  3. Geoff
    Geoff avatar
    89 posts
    Registered:
    02 Mar 2011
    24 Mar 2011
    Link to this post
    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".
  4. Geoff
    Geoff avatar
    89 posts
    Registered:
    02 Mar 2011
    24 Mar 2011
    Link to this post
    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.
  5. Bonny
    Bonny avatar
    58 posts
    Registered:
    11 Nov 2016
    24 Mar 2011
    Link to this post
    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
    Answered
  6. Geoff
    Geoff avatar
    89 posts
    Registered:
    02 Mar 2011
    24 Mar 2011
    Link to this post
    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.
  7. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    29 Mar 2011
    Link to this post
    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
  8. Geoff
    Geoff avatar
    89 posts
    Registered:
    02 Mar 2011
    29 Mar 2011
    Link to this post
    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.
  9. Bonny
    Bonny avatar
    58 posts
    Registered:
    11 Nov 2016
    01 Apr 2011
    Link to this post
    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
9 posts, 2 answered