lingdanglfw(DAX)

导航

Workflow in Dynamics AX2009

示例流程:创建Sales Order时,若产品总额超过该客户的Credit Limit,则需进行审核

一、创建Workflow Category

展开AOT中的workflow,右键Workflow Categories,选择“New Workflow Category”, 并修改其属性

 

修改"Name", 需指定其所属Module,此例中为“SalesOrder”

 

二、创建Query

在AOT中右键Queries选择“New Query”, 并进行重命名

 

打开一个新的AOT,在Data Dictionary下找到SalesTable, 并拖拉至新创建的Query的Data Source中

 

修改Data Source下的Sales Table_1中Fields的属性,将"Dynamic"改为"Yes"

三、创建Workflow Type

右键AOT中Workflow Type, 选择“”Add-ins"->"Workflow type wizard..."

在弹出的窗口中填写“Name, Category, Query, Document menu item”等信息

Category选择刚创建的Workflow Category, Query选择刚创建的Query, Document menu item选择SalesTable

 

系统会自动进行创建

 

创建完成后,会自动生成WF Project, 包括“Workflow Type”, "Classes"和“Menu Items”

四、在窗体中启用Workflow

增加WorkflowState的Field

右键AOT中Data Dictionary下的Base Enums, 选择"New Base Enums"

 

重命名,并在其下新建四个element

 

分别为"NotSubmitted", "Submitted", "Approved", "Rejected"

 

找到SalesTable, 右键"Field", 选择“New”->"Enum"

 

修改其属性,将Enum Type指向刚创建的Base Enum

 

在窗体上启用Workflow

找到SalesTable, 创建一个新的Method

 

内容如下:

 

boolean canSubmitToWorkflow(str _workflowType='')
{
    amountMST creditBalance;
    CustTable custTable;
    ;
    if(!this.GMC_CreditLimitApprovalStatus==GMC_SalesCreditLimitApprovalStatus::NotSubmitted)
        return false;
    custTable = this.custTable_InvoiceAccount();
    if(!custTable.CreditMax)
        return false;
    creditBalance=custTable.CreditMax - custTable.balanceMST();
    if(this.amountRemainSalesFinancial()+this.amountRemainSalesPhysical() <creditBalance)
        return false;
    return true;
}

 

 

 

 

 

 

 

 

在Forms下找到SalesTableListPage, 点击“Designs”, 右键“Design”, 并修改其属性

WorkflowEnabled 改为"Yes", WorkflowDatasource选择"SalesTable", WorkflowType选择此例中创建的WokflowType

 

五、在Workflow Class中创建Submit方法

通过"Ctrl+Shift+P"打开Project窗口,在"Private"下双击此例中创建的WFType Project,在Classes下右键Submitmanager, 选择"New"->"Method"

代码示例:

void submit (Args args)
{
    //Variable declaration
    RecId recId = args.record().RecId;
    WorkflowCorrelationId workflowCorrelationId;
    //Hardcoded type name
   WorkflowTypeName workflowTypeName = workFlowTypeStr(GMC_SalesCreditLitmi);
    //Initial note is the information that users enter when they submit the document for workflow
   WorkflowComment note = "";
   WorkflowSubmitDialog workflowSubmitDialog;
    SalesTable salesTable;
    //Opens the submit to workflow dialog.
    workflowSubmitDialog = workflowSubmitDialog::construct(args.caller().getActiveWorkflowConfiguration());
    workflowSubmitDialog.run();
    if(workflowSubmitDialog.parmIsClosedOK())
    {
        recId = args.record().RecId;
        salesTable = args.record();
        //Get comments from the submit to workflow dialog
        note = workflowSubmitDialog.parmWorkflowComment();
        try
        {
            ttsBegin;
            workflowCorrelationId = Workflow::activateFromWorkflowType(workflowTypeName, recId, note, NoYes::No);
            salesTable.GMC_CreditLimitApprovalStatus = GMC_SalesCreditLimitApprovalStatus::Submitted;
            //Send an Infolog message
            info("Submitted to workflow.");
            ttsCommit;
    }
        catch(Exception::Error)
        {
            info("Error on workflow activation.");
        }
    }
    args.caller().updateWorkFlowControls();

}

 

保存并Compile,在Menu Item下找到此例的SubmitMenuItem, 将其Label改为"Submit"

 

六、创建Workflow Approval

右键Workflow下的Approvals, 选择Add-ins -> Approval wizard

点击Next

输入Name, Workflow Document选择此例中创建的,Document preview field group选择Overview, Document menu item选择SalesTableListPage

 

系统进行自动创建

 

 

创建完成后生成的Project

 

将Approval Element下的“”GMC_SalesCLApproval"拖至Workflow Type下的Supported Element中

 

七、创建Event Handlers

Event Handler代码

在WFType Project中,找到EventHandler Class, 将代码写入其completed方法中

代码示例:

 

public void completed(WorkflowEventArgs _workflowEventArgs)
{
    SalesTable salesTable;
    select forUpdate SalesTable where SalesTable.RecId == _workflowEventArgs.parmWorkflowContext().parmRecId();
    if(salesTable.RecId)
    {
        salesTable.GMC_CreditLimitApprovalStatus = GMC_SalesCreditLimitApprovalStatus::Approved;
        salesTable.write();
    }
}

 

 

 

 

 

 

创建Element Level Event Handlers

在WorkflowApproval Project中,找到ApprovalEventHandler, 将代码写入其Returned方法中

代码示例:

 

public void returned(WorkflowElementEventArgs _workflowElementEventArgs)
{
    SalesTable salesTable;
    ttsBegin;
    select forUpdate salesTable where salesTable.RecId == _workflowElementEventArgs.parmWorkflowContext().parmRecId();
    salesTable.GMC_CreditLimitApprovalStatus = GMC_SalesCreditLimitApprovalStatus::Rejected;
    salesTable.update();
    ttsCommit;
}

 

 

 

 

 

右键AOT,选择Incremental CIL generation from X++

完成后会有提示

 

八、Author a Workflow

创建新的Display menu item, 并修改其属性

Label: Sales and marketing workflows

Object:WorkflowTableListPage

EnumTypeParameter: ModuleAxapta

EnumParameter: SalesOrder

 

将此menu item添加至SalesAndMarketing的Setup下,并将IsDisplayedInContentArea 改为 Yes

 

在Module Sales and Marketing的Setup中,找到sales and marketing workflow 并打开,创建一个新的workflow, 可以看到Workflow Type中出现了此例中创建的workflow

 

在Account receivable模块中,也有该workflow

 

新建workflow,将"Approvals"下的项拖至设计器中,并处于Start和End之间

 

双击该Approval节点,配置审核人等信息

 
 
输入Name, Subject和Instructions
 
 

九、流程测试

先查看某一customer的credit limit的信息,并记录

 

创建新的Sales Order, 选择该customer, 并将产品总额设置超过其credit limit,则系统会进行提示

 

查看该条Sales Order记录,可看到上方黄色条右方的"Submit"按钮

posted on 2021-08-24 17:54  lingdanglfw  阅读(81)  评论(0编辑  收藏  举报