Sunday, May 19, 2019

Workflow process in AX 2012


Step1: Create approval status (Enum type)
Step2: Add into respective Table
Step3: Add this table into respective workflow Form
            OR Sync the Form datasource if existing table
Step4: Override the “CanSubmitToWorkflow”  method in table
Table Level:

public boolean canSubmitToWorkflow(str _workflowType = '')
{
    boolean ret;
   
    if (!this.ApprovalStatus == ApprovalStatus::NotSubmitted)

    return false;

    else

    return true;
 
}
Step 5: Create AOT query
Step 6: Create Workflow category and select the module which is required for workflow
Step 7: Create Workflow type through wizard

WorkFlow Type Classes:
Workflow Submit method:
public static void main(Args args)
{
    // Variable declaration.
    recId recId = args.record().RecId;
    WorkflowCorrelationId workflowCorrelationId;
    // Hardcoded type name
    WorkflowTypeName workflowTypeName =workflowtypestr(RecruitmentProj);
    // Initial note is the information that users enter when they

    // submit the document for workflow.
    WorkflowComment note ="";
    WorkflowSubmitDialog workflowSubmitDialog;
    HRMRecruitingTable  hrmRecruitingTable;

    // Opens the submit to workflow dialog.
    workflowSubmitDialog =
    WorkflowSubmitDialog::construct(args.caller().getActiveWorkflowConfiguration());
    workflowSubmitDialog.run();
    if (workflowSubmitDialog.parmIsClosedOK())
    {
        recId = args.record().RecId;

        hrmRecruitingTable = args.record();
        // Get comments from the submit to workflow dialog.
        note = workflowSubmitDialog.parmWorkflowComment();
        try
        {
            ttsbegin;
            workflowCorrelationId =Workflow::activateFromWorkflowType(workflowTypeName,recId,note,NoYes::No);
            hrmRecruitingTable.ApprovalStatus = ApprovalStatus::Submitted;

            // Send an Infolog message.
            info("Submitted to workflow.");
            ttscommit;
        }
        catch(exception::Error)
        {
            info("Error on workflow activation.");
        }
    }
    args.caller().updateWorkFlowControls();
}

Approved event handler:
public void completed(WorkflowEventArgs _workflowEventArgs)
{
    HRMRecruitingTable hrmrecruitingTable;
    select forupdate hrmrecruitingTable where hrmrecruitingTable.RecId == _workflowEventArgs.parmWorkflowContext().parmRecId();
    if(hrmrecruitingTable.RecId)
    {
        hrmrecruitingTable.ApprovalStatus = ApprovalStatus::Approved;
        hrmrecruitingTable.update();
    }
}

Step 8: Create Workflow Approval through wizard:
Approval Classes:
Resubmit :
public static void main(Args args)
{
    // Variable declaration.
    recId recId = args.record().RecId;
    WorkflowCorrelationId _workflowCorrelationId;
    // Hardcoded type name
    WorkflowTypeName _workflowTypeName = workflowtypestr(RecruitmentProj);
    // Initial note is the information that users enter when they
    // submit the document for workflow.
    WorkflowComment _initialNote ="";
    WorkflowWorkItemActionDialog
    WorkflowWorkItemActionDialog;
    HRMRecruitingTable  hrmRecruitingTable;
    ;
    // Opens the submit to workflow dialog.
    workflowWorkItemActionDialog = WorkflowWorkItemActionDialog::construct(args.caller().getActiveWorkflowWorkItem(),
                                                                            WorkflowWorkItemActionType::Resubmit,
                                                                            new MenuFunction(menuitemactionstr(RecruitmentProjApprResubmitMenuItem),
                                                                            MenuItemType::Action));
    workflowWorkItemActionDialog.run();
    if (WorkflowWorkItemActionDialog.parmIsClosedOK())
    {
        recId = args.record().RecId;
        hrmRecruitingTable = args.record();
        // Get comments from the submit to workflow dialog.
        _initialNote = workflowWorkItemActionDialog.parmWorkflowComment();
        try
        {
            ttsbegin;
            WorkflowWorkItemActionManager::dispatchWorkItemAction(args.caller().getActiveWorkflowWorkItem(),
                                                                    _initialNote,
                                                                    curUserId(),
                                                                    WorkflowWorkItemActionType::Resubmit,
                                                                    args.menuItemName(),
                                                                    false);
            hrmRecruitingTable.ApprovalStatus = ApprovalStatus::Submitted;
            // Send an Infolog message.
            info("Resubmitted to workflow.");
            ttscommit;
        }
        catch(exception::Error)
        {
        info("Error on workflow activation.");
        }
    }
    args.caller().updateWorkFlowControls();
}

Returned (Rejected) Logic:
public void returned(WorkflowElementEventArgs _workflowElementEventArgs)
{
    HRMRecruitingTable hrmrecruitingTable;
    select forupdate hrmrecruitingTable where hrmrecruitingTable.RecId == _workflowElementEventArgs.parmWorkflowContext().parmRecId();
    if(hrmrecruitingTable.RecId)
    {
        hrmrecruitingTable.ApprovalStatus = ApprovalStatus::Rejected;
        hrmrecruitingTable.update();
    }
}
Step 9: Drag And Drop workflow approval element from workflow approvals in to supported elements under workflow type
Step 10: Apply this workflow to our form by going to design properties
Workflow enabled: Yes
Worflow Datasource:
Workflow Type:
Step 11:
Create New Menu item (Check the document).
Step 12:
Configuring Workflow

No comments:

Post a Comment