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

Forums / Developing with Sitefinity / Programmatic use of workflow with notification

Programmatic use of workflow with notification

3 posts, 0 answered
  1. Scott Rozman
    Scott Rozman avatar
    93 posts
    Registered:
    10 Oct 2012
    29 Aug 2014
    Link to this post

    I am working on a project with many data types created with the Module Builder.

    I have a workflow enabled which generates emails when using the Sitefinity backend.

    Now I am trying to use the workflow and notifications from buttons on the frontend.

    I've been using IApprovalWorkflow.SetWorkflowStatus to change to "AwaitingApproval" etc. and then dynamicModuleBuilder.SaveChanges(). That was fine, but I also need to generate emails for Submit, Approve and Reject.

    I found this:

    http://www.sitefinity.com/documentation/documentationarticles/pass-a-dynamic-item-through-workflow-notification-system-programmatically

    and tried to add the "Send Item for Approval" to my code, but an email is not generated and there are no exceptions.

    Does anyone have a sample of doing this with Module Builder data?

    thanks in advance, 

    Scott

  2. Vassil Vassilev
     Vassil Vassilev avatar
    308 posts
    Registered:
    21 Jan 2015
    03 Sep 2014
    Link to this post
    Hello Scott,

    I believe this could easiest achieved using custom workflow and there is a sample to what I believe you are trying to achieve here: Implement custom workflow activity

    Hope this helps.

    Regards,
    Vassil Vassilev
    Telerik
     
    Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Sitefinity CMS Ideas&Feedback Portal and vote to affect the priority of the items
     
  3. Scott Rozman
    Scott Rozman avatar
    93 posts
    Registered:
    10 Oct 2012
    03 Sep 2014 in reply to Vassil Vassilev
    Link to this post

    Thank you, Vassil. I have seen the information you posted, however I have two needs.

    1) I cannot get the default workflow to run from my code.

    2) I will also want to modify the content of the email, so that the notes about the state change are in the email.

    Please see the code I am using for the custom submit button. Notes are normally saved for Rejected items only, but I am saving a note for Awaiting Approval, Rejected and Published. My "UnitEditable" field is controlling the ability to modify drafts on many other content types which act as multiple children to the one for which I am trying to create notifications.

    The lines which are commented were not working for module builder data.

     Thank you, Scott

    public string SubmitBudget(DynamicContent currentBudgetItem, string notes)
            {
                try
                {
                    if (currentBudgetItem.ApprovalWorkflowState != "AwaitingApproval")
                    {
     
                        var master = dynamicModuleManager.Lifecycle.GetMaster(currentBudgetItem) as DynamicContent;
                        var checkOutBudgetItem = dynamicModuleManager.Lifecycle.CheckOut(master) as DynamicContent;
                        checkOutBudgetItem.SetValue("UnitEditable", false);
                        ILifecycleDataItem checkInCourseItem = dynamicModuleManager.Lifecycle.CheckIn(checkOutBudgetItem);
                        dynamicModuleManager.SaveChanges();
                        IApprovalWorkflowExtensionsApm.SetWorkflowStatusApm(currentBudgetItem,
                            dynamicModuleManager.Provider.ApplicationName, "AwaitingApproval", null,
                            notes);
                        dynamicModuleManager.SaveChanges();
                        //send item for approval
                        //var holder = new Dictionary<string, string>();
                        //holder.Add("ContentType", budgetType.FullName);
                        //WorkflowManager.MessageWorkflow(master.Id, budgetType, dynamicModuleManager.Provider.ToString(), "SendForApproval", false, holder);
     
                        return apmAlerts.Success("The current budget has been submitted for approval.");
                    }
                    else
                    {
                        return apmAlerts.Warning("The current budget was already awaiting approval.");
                    }
                }
             
                catch (Exception e)
                {
     
                    return apmAlerts.Error("There was a problem submitting this budget for approval.<br />" + e.ToString());
                }
            }

3 posts, 0 answered