Workflow in Dynamics AX2009

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

一、创建Workflow Category

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

Workflow in Dynamics AX2009

 

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

Workflow in Dynamics AX2009

 

二、创建Query

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

Workflow in Dynamics AX2009

Workflow in Dynamics AX2009

 

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

Workflow in Dynamics AX2009

 

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

Workflow in Dynamics AX2009

三、创建Workflow Type

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

Workflow in Dynamics AX2009

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

Workflow in Dynamics AX2009

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

Workflow in Dynamics AX2009

 

系统会自动进行创建

Workflow in Dynamics AX2009

Workflow in Dynamics AX2009

 

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

Workflow in Dynamics AX2009

四、在窗体中启用Workflow

增加WorkflowState的Field

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

Workflow in Dynamics AX2009

 

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

Workflow in Dynamics AX2009

 

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

Workflow in Dynamics AX2009

 

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

Workflow in Dynamics AX2009

 

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

Workflow in Dynamics AX2009

 

在窗体上启用Workflow

找到SalesTable, 创建一个新的Method

Workflow in Dynamics AX2009

 

内容如下:

 

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;
}

 

 

 

 

 

 

 

Workflow in Dynamics AX2009

 

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

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

Workflow in Dynamics AX2009

 

五、在Workflow Class中创建Submit方法

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

Workflow in Dynamics AX2009

代码示例:

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();

}

Workflow in Dynamics AX2009

 

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

Workflow in Dynamics AX2009

 

六、创建Workflow Approval

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

Workflow in Dynamics AX2009

点击Next

Workflow in Dynamics AX2009

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

Workflow in Dynamics AX2009

 

系统进行自动创建

Workflow in Dynamics AX2009

 

Workflow in Dynamics AX2009

 

创建完成后生成的Project

Workflow in Dynamics AX2009

 

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

Workflow in Dynamics AX2009

 

七、创建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();
    }
}

 

 

 

 

 

Workflow in Dynamics AX2009

 

创建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;
}

 

 

 

 

Workflow in Dynamics AX2009

 

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

Workflow in Dynamics AX2009

完成后会有提示

Workflow in Dynamics AX2009

 

八、Author a Workflow

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

Label: Sales and marketing workflows

Object:WorkflowTableListPage

EnumTypeParameter: ModuleAxapta

EnumParameter: SalesOrder

Workflow in Dynamics AX2009

 

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

Workflow in Dynamics AX2009

 

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

Workflow in Dynamics AX2009

 

在Account receivable模块中,也有该workflow

Workflow in Dynamics AX2009

 

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

Workflow in Dynamics AX2009

 

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

Workflow in Dynamics AX2009

  Workflow in Dynamics AX2009   输入Name, Subject和Instructions Workflow in Dynamics AX2009    

九、流程测试

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

Workflow in Dynamics AX2009

 

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

Workflow in Dynamics AX2009

 

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

Workflow in Dynamics AX2009

上一篇:D365FO Tool – Automating Start and Stop Environments


下一篇:Flutter 热加载和热重启的区别reload restart