Monday, December 13, 2010

Enable workflow in a Dynamics Ax webpart (EP)


First create a new dynamics webpart in .net. Need to perform few steps to enable the workflow in the required webpart.
a.  Register workflow control in webpart.
    <%@ 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" %>
b.  Add workflow control in webpart (place the code after datasource).
    <dynamics:AxWorkflowActionBar ID="WorkflowActionBar" runat="server" DataSourceID="AxDataSource1" DataMember="{TableName}_Current" />
C.  Under Editor, call the following namespace
   using Microsoft.Dynamics.Framework.Portal.UI.WebControls.Workflow;
d.  Create the following method for calling CanSubmitToWorkflow method by using Proxy.
   void WorkflowActionBar_EvaluatingCanSubmitToWorkflow(object sender, EvaluatingCanSubmitToWorkflowEventArgs e)
         {
            Boolean canSubmit;
            IAxaptaRecordAdapter record = e.DocumentRecord;
ApplicationProxy.TM_PolicyMaster policyMaster = new                     ApplicationProxy.PolicyMaster(this.AxSession.AxaptaAdapter, record);
        canSubmit = (Boolean)policyMaster.canSubmitToWorkflow();

        e.CanSubmitToWorkflow = canSubmit;
   }
      (Note: Here PolicyMaster the Ax Table and canSubmitToWorkflow method is under the table and it is defined in proxy also. It returns boolean)
 e.  Create or update the page init method in webpart editor with following code
     void Page_Init(object sender, EventArgs e
     {       
          this.WorkflowActionBar.EvaluatingCanSubmitToWorkflow += new EventHandler<EvaluatingCanSubmitToWorkflowEventArgs>(WorkflowActionBar_EvaluatingCanSubmitToWorkflow);
      }
f.  Create three WebActionMenuItems in DAX with EPWorkflowWorkItemActionManager class.
     Set label: Web Approve, Web Reject and Web request to Change
     Set Run On = Called from
g.  Create another two WebActionMenuItems in DAX with your created Submit class.
    Set label: Web Submit and Web Re-submit.
h.  Modify Submit class for Submitting workflow.
    DialogOk, init and reSubmit method
Figure 1: DialogOK() of submit class, write this code after menuIten calls. Here “EP_PolicySubmit” and “EP_PolicyReSubmit” are the WebActionMenuItem of EPWorkflowWorkItemActionManager.

Figure 2: Init() method of submit class: Add the highlighted line with your web policy submit menuItem name


                  
Figure 3: ReSubmit method of submit class: Add the highlighted line with your web policy Re-Submit menuItem name

i.       Now set the webmenuItems in different places….
       a.       Web Submit: Workflow Template (Properties) ->  submitToWorkflowWebMenuItem
         b.      Web Re-Submit: Workflow Approval (Properties) -> ReSubmitWebMenuItem
         c.       Web  Approve: Workflow Approval ->Outcomes->Approve (Propeties) -> ActionWebMenuItem
        d.      Web  Reject: Workflow Approval ->Outcomes->Reject (Propeties) -> ActionWebMenuItem
        e.      Web  Req. to Change: Workflow Approval ->Outcomes-> RequestChange (Propeties) -> ActionWebMenuItem

And now workflow is ready for web. Please reset the IIS and Refresh AOD from EP before the submit of Workflow.  



1 comment:

sksingh1 said...

This is another blog which i get very useful for dynamics learner


http://daynamicsaxaptatutorials.blogspot.com/