Thursday, 14 July 2011

How to enable workflow on EP form


Add an Assembly Reference

Select the AXUserControl on which you want to enable workflow then right click & select View Markup. Add the following lines to View Markup. 

<%@ Register Assembly="Microsoft.Dynamics.Framework.Portal, Version=5.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
    Namespace="Microsoft.Dynamics.Framework.Portal.UI.WebControls.Workflow" TagPrefix="dynamics" %>

Add AXWorkflowActionBar

Add the following lines to the View Markup.

This is the Data bound control, the DataMember & DataSourceID must be set according to your scenario. DataMember property must be set the table on which the workflow enabled.
 
<dynamics:AxWorkflowActionBar ID="WorkflowActionBar" runat="server"   
    DataMember="SalesTable_Current"     DataSourceID="dsEPSalesTableList"  >
</dynamics:AxWorkflowActionBar>



Add Namespace


To implement the methods related to workflow control in the code sheet(C# code sheet)add the following line.
using Microsoft.Dynamics.Framework.Portal.UI.WebControls.Workflow;

Changes to do in AX
Set the property 'SubmitToWorkflowWebMenuItem' of corresponding workflow template as shown below.


 

Set the property 'DocumentWebMenuItem' of corresponding workflow Approvals as shown below.



Create Action Web Menu Items for Approve, Reject & Deny as shown below.
  
 Assign the newly created Action Web Menu Items to Approvals -> Approve,Reject & Deny as shown below.

 

Adding code to support Enterprise Portal Workflow Submission

Add the following code in Workflow submit class of submission method.


Write a method on SalesTable canSubmitToWorkflow


Add this method to Proxy and Generate Proxy.

Evaluating CanSubmitToWorkflow Event in C# Code

This event fire when control is attempting to determine if the current record is in a state to be submitted to workflow. The control does not have knowledge of the state of the document so the developer has to subscribe this event.


void Page_Init(object sender, EventArgs e)
{
    //Subscribe to the EvaluatingCanSubmitToWorkflow event
this.WorkflowActionBar.EvaluatingCanSubmitToWorkflow += new   EventHandler<EvaluatingCanSubmitToWorkflowEventArgs>(WorkflowActionBar_EvaluatingCanSubmitToWorkflow);
}

void WorkflowActionBar_EvaluatingCanSubmitToWorkflow(object sender, EvaluatingCanSubmitToWorkflowEventArgs e)
{
    // Evaluate state of document and set value to true or false
IAxaptaRecordAdapter record = e.DocumentRecord;
ApplicationProxy.SalesTable salesTable = new ApplicationProxy.SalesTable(this.AxSession.AxaptaAdapter, record);
if (salesTable.canSubmitToWorkflow())
   e.CanSubmitToWorkflow = true;
}