Programmatic use of workflow with notification
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:
www.sitefinity.com/.../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
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
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());