Thursday 18 September 2014

Workflow Process methods in ax 2012

Table level method :
boolean canSubmitToWorkflow(str _workflowType = '')
{
    boolean     canSubmit = false;
    ;
    if (!this.SubDealerApprovalStatus  == SubDealerApprovalStatus::NotSubmitted)
    {
        return false;
    }
    return true;
}

Public static void setWorkflowState (RecId _RecId,
                             SPL_SalesMarketStatus _SPL_SalesMarketStatus)
{
    smmBusRelTable            smmBusRelTable,smmBusRelTableloc;

    Ttsbegin;

   select  smmBusRelTableloc where smmBusRelTableloc.RecId == _RecId;
   select forUpdate  smmBusRelTable where smmBusRelTable.RecId == smmBusRelTableloc.RecId;
   smmBusRelTable.SPL_SalesMarketStatus= _SPL_SalesMarketStatus;

    Switch (_SPL_SalesMarketStatus)
    {

        Case SPL_SalesMarketStatus::Notsubmitted:
             smmBusRelTable.SPL_SalesMarketStatus = SPL_SalesMarketStatus::Notsubmitted;
             Break;

        Case SPL_SalesMarketStatus::Submitted:
            smmBusRelTable.SPL_SalesMarketStatus = SPL_SalesMarketStatus::Submitted;
             Break;

        Case SPL_SalesMarketStatus::Approved:
            smmBusRelTable.SPL_SalesMarketStatus = SPL_SalesMarketStatus::Approved;
             Break;

        case SPL_SalesMarketStatus::Rejected:
            smmBusRelTable.SPL_SalesMarketStatus = SPL_SalesMarketStatus::Rejected;
             Break;


        Case SPL_SalesMarketStatus::ChangeRequested:
             smmBusRelTable.SPL_SalesMarketStatus = SPL_SalesMarketStatus::ChangeRequested;
             Break;

        Default:
           Break;
    }
   smmBusRelTable.update();
    Ttscommit;
}

_____________________
Class methods:
class SubDealApprovalEventHandler implements    WorkflowElementCanceledEventHandler,     WorkflowElemChangeRequestedEventHandler,
                                                        WorkflowElementCompletedEventHandler, WorkflowElementReturnedEventHandler,
                                                        WorkflowElementStartedEventHandler, WorkflowElementDeniedEventHandler,
                                                        WorkflowWorkItemsCreatedEventHandler
{
}
public void canceled(WorkflowElementEventArgs _workflowElementEventArgs)
{
     smmBusRelTable        smmBusRelTable;
    ttsBegin;
    select forupdate smmBusRelTable where smmBusRelTable.RecId ==
        _workflowElementEventArgs.parmWorkflowContext().parmRecId();
    if (smmBusRelTable.recid)
    {
        smmBusRelTable.SubDealerApprovalStatus = SubDealerApprovalStatus::canceled;
        smmBusRelTable.update();
    }
    ttsCommit;
}
public void changeRequested(WorkflowElementEventArgs _workflowElementEventArgs)
{
     smmBusRelTable        smmBusRelTable;
    ttsBegin;
    select forupdate smmBusRelTable where smmBusRelTable.RecId ==
        _workflowElementEventArgs.parmWorkflowContext().parmRecId();
    if (smmBusRelTable.recid)
    {
        smmBusRelTable.SubDealerApprovalStatus = SubDealerApprovalStatus::ChangeRequested;
        smmBusRelTable.update();
    }
    ttsCommit;
}
public void completed(WorkflowElementEventArgs _workflowElementEventArgs)
{
     smmBusRelTable        smmBusRelTable;
    ttsBegin;
    select forupdate smmBusRelTable where smmBusRelTable.RecId ==
        _workflowElementEventArgs.parmWorkflowContext().parmRecId();
    if (smmBusRelTable.recid)
    {
        smmBusRelTable.SubDealerApprovalStatus = SubDealerApprovalStatus::Approved;
        smmBusRelTable.update();
    }
    ttsCommit;
}
public void denied(WorkflowElementEventArgs _workflowElementEventArgs)
{

     smmBusRelTable        smmBusRelTable;
    ttsBegin;
    select forupdate smmBusRelTable where smmBusRelTable.RecId ==
        _workflowElementEventArgs.parmWorkflowContext().parmRecId();
    if (smmBusRelTable.recid)
    {
        smmBusRelTable.SubDealerApprovalStatus = SubDealerApprovalStatus::Rejected;
        smmBusRelTable.update();
    }
    ttsCommit;
}
public void returned(WorkflowElementEventArgs _workflowElementEventArgs)
{
     smmBusRelTable        smmBusRelTable;
    ttsBegin;
    select forupdate smmBusRelTable where smmBusRelTable.RecId ==
        _workflowElementEventArgs.parmWorkflowContext().parmRecId();
    if (smmBusRelTable.recid)
    {
        smmBusRelTable.SubDealerApprovalStatus = SubDealerApprovalStatus::Rejected;
        smmBusRelTable.update();
    }
    ttsCommit;
}
public void started(WorkflowElementEventArgs _workflowElementEventArgs)
{
     smmBusRelTable        smmBusRelTable;
    ttsBegin;
    select forupdate smmBusRelTable where smmBusRelTable.RecId ==
        _workflowElementEventArgs.parmWorkflowContext().parmRecId();
    if (smmBusRelTable.recid)
    {
        smmBusRelTable.SubDealerApprovalStatus = SubDealerApprovalStatus::Submitted;
        smmBusRelTable.update();
    }
    ttsCommit;
}
___________________
class SubDealerApprDocument extends WorkflowDocument
{
}
public queryName getQueryName()
{
    return querystr(SubDealerApproval);
}
______________
class SubDealerApprEventHandler implements    WorkflowCanceledEventHandler,  WorkflowCompletedEventHandler,
                                                        WorkflowStartedEventHandler
{
}
public void canceled(WorkflowEventArgs _workflowEventArgs)
{

    smmBusRelTable        smmBusRelTable;
    ttsBegin;
    select forupdate smmBusRelTable where smmBusRelTable.RecId ==
        _workflowEventArgs.parmWorkflowContext().parmRecId();
    if (smmBusRelTable.recid)
    {
        smmBusRelTable.SubDealerApprovalStatus = SubDealerApprovalStatus::Rejected;
        smmBusRelTable.update();
    }
    ttsCommit;
}
public void completed(WorkflowEventArgs _workflowEventArgs)
{
    smmBusRelTable        smmBusRelTable;
    ttsBegin;
    select forupdate smmBusRelTable where smmBusRelTable.RecId ==
        _workflowEventArgs.parmWorkflowContext().parmRecId();
    if (smmBusRelTable.recid)
    {
        smmBusRelTable.SubDealerApprovalStatus = SubDealerApprovalStatus::Approved;
        smmBusRelTable.update();
    }
    ttsCommit;
}
public void started(WorkflowEventArgs _workflowEventArgs)
{
    smmBusRelTable        smmBusRelTable;
    ttsBegin;
    select forupdate smmBusRelTable where smmBusRelTable.RecId ==
        _workflowEventArgs.parmWorkflowContext().parmRecId();
    if (smmBusRelTable.recid)
    {
        smmBusRelTable.SubDealerApprovalStatus = SubDealerApprovalStatus::Submitted;
        smmBusRelTable.update();
    }
    ttsCommit;
}
_________
public class SubDealerApprSubmitManager
{
}
public static void main(Args args)
{
    SubDealerApprSubmitManager   Submitmanager =new  SubDealerApprSubmitManager();
    ;
    Submitmanager.submit(args);
}
void submit(Args args)
{
    // Variable declaration.
    recId recId = args.record().RecId;
    WorkflowCorrelationId workflowCorrelationId;
    // Hardcoded type name
    WorkflowTypeName workflowTypeName =workflowtypestr(SubDealerAppr);
    // Initial note is the information that users enter    when they
    // submit the document for workflow.
    WorkflowComment note ="";
    WorkflowSubmitDialog workflowSubmitDialog;
    smmBusRelTable smmBusRelTablelocal;
    // Opens the submit to workflow dialog.
    workflowSubmitDialog = WorkflowSubmitDialog::construct(args.caller().getActiveWorkflowConfiguration());
    workflowSubmitDialog.run();
    if (workflowSubmitDialog.parmIsClosedOK())
    {
        recId = args.record().RecId;
        smmBusRelTablelocal = args.record();
        if(!smmBusRelTablelocal.CustGroup)
        {
            throw error("Please select the customer group");
        }
        // Get comments from the submit to workflow dialog.
        note = workflowSubmitDialog.parmWorkflowComment();
        try
        {
            ttsbegin;
                workflowCorrelationId = Workflow::activateFromWorkflowType(workflowTypeName,recId,note,NoYes::No);
                smmBusRelTablelocal.SubDealerApprovalStatus = SubDealerApprovalStatus::Submitted;
                smmBusRelTablelocal.update();
                // Send an Infolog message.
               // info("Submitted to workflow.");
            ttscommit;
        }
        catch(exception::Error)
        {
            info("Error on workflow activation.");
        }
    }
    args.caller().updateWorkFlowControls();
}
____________________________________
Public class SPL_SalesMarApprovalResubmitActionMgr
{
    smmBusRelTable            smmBusRelTable;

    RecId                       vendtableid;
    WorkflowVersionTable        workflowVersionTable;
    WorkflowComment             workflowComment;
    Boolean                     submit;
    WorkflowWorkItemTable       workflowWorkItemTable;
    UserId                      userId;
    MenuItemName                menuItemName;
    EPWorkflowControlContext    workflowControlContext;
    WorkflowTypeName            workflowTemplateName;
}

Public Boolean dialogOk ()
{
    WorkflowSubmitDialog            workflowSubmitDialog;
    WorkflowWorkItemActionDialog    workflowWorkItemActionDialog;
    Boolean                         ok;


     If (menuItemName == menuitemActionStr(SPL_SalesMarApprovalResubmitMenuItem))
    {
        WorkflowWorkItemActionDialog = WorkflowWorkItemActionDialog::construct(
                                            WorkflowWorkItemTable,
                                            WorkflowWorkItemActionType::Resubmit,
                                            New MenuFunction (menuitemActionStr (SPL_SalesMarApprovalResubmitMenuItem), MenuItemType::Action));

        workflowWorkItemActionDialog.run ();
        this.parmWorkflowComment(workflowWorkItemActionDialog.parmWorkflowComment ());
        Ok = workflowWorkItemActionDialog.parmIsClosedOK();
        UserId = workflowWorkItemActionDialog.parmTargetUser();
    }
    if(Ok == true)
    {
        Ok = true;
    }
    else
    {
        Ok = false;
    }


    Return ok;
}

Public void init (RecId                       _documentRecordId,
    MenuItemName                _menuItemName,
    WorkflowVersionTable        _workflowVersionTable,
    WorkflowWorkItemTable       _workflowWorkItemTable,
    EPWorkflowControlContext    _workflowControlContext)
{
    If (_documentRecordId)
    {
        this.parmvendtableid(_documentRecordId);
        this.parmSubmit(_menuItemName == menuitemActionStr(SPL_SalesMarketApprSubmitMenuItem));
        this.parmMenuItemName(_menuItemName);

        If (_workflowControlContext)
        {
            this.parmWorkflowControlContext(_workflowControlContext);
            this.parmWorkflowWorkItemtable(_workflowControlContext.getActiveWorkflowWorkItem());
            this.parmWorkflowComment(_workflowControlContext.getWorkflowComment());
            this.parmWorkflowTemplateName(_workflowControlContext.getActiveWorkflowConfiguration().workflowTable().TemplateName);
        }
        Else
        {
            this.parmWorkflowVersionTable(_workflowVersionTable);
            this.parmWorkflowWorkItemtable(_workflowWorkItemTable);
            this.parmWorkflowTemplateName(this.parmWorkflowVersionTable().workflowTable().TemplateName);
        }
    }
}

Public menuItemName parmMenuItemName (menuItemName _menuItemName = menuItemName)
{
    MenuItemName = _menuItemName;
    Return menuItemName;
}


Public Boolean parmSubmit (Boolean _submit = submit)
{
    Submit = _submit;
    Return submit;
}

Public RecId parmvendtableid (RecId _vendtableid = VendTableid)
{
    VendTableid = _vendtableid;

    Return vendtableid;
}

Public WorkflowComment parmWorkflowComment (WorkflowComment _workflowComment = workflowComment)
{
    WorkflowComment = _workflowComment;
    Return workflowComment;
}

Public EPWorkflowControlContext parmWorkflowControlContext (EPWorkflowControlContext _workflowControlContext = workflowControlContext)
{
    WorkflowControlContext = _workflowControlContext;
    Return workflowControlContext;
}

Public workflowTypeName parmWorkflowTemplateName (workflowTypeName _workflowTemplateName = workflowTemplateName)
{
    WorkflowTemplateName = _workflowTemplateName;
    Return workflowTemplateName;
}

Public WorkflowVersionTable parmWorkflowVersionTable (WorkflowVersionTable _workflowVersionTable = workflowVersionTable)
{
    workflowVersionTable = _workflowVersionTable;
    Return workflowVersionTable;
}

Public WorkflowWorkItemTable parmWorkflowWorkItemtable (WorkflowWorkItemTable _workflowWorkItemTable = workflowWorkItemTable)
{
    ;
    WorkflowWorkItemTable = _workflowWorkItemTable;

    Return workflowWorkItemTable;
}

Public void reSubmit()
{
WorkflowWorkItemActionManager::dispatchWorkItemAction (WorkflowWorkItemTable,WorkflowComment, UserId, WorkflowWorkItemActionType::Resubmit, MenuItemName,
 MenuItemName == webActionItemStr (EPCustFreeInvoiceReSubmit));

    smmBusRelTable::setWorkflowState(vendtableid, SPL_SalesMarketStatus::Submitted);
}

Public void submit()
{
    NoYes               activatingFromWeb;

    ActivatingFromWeb = this.parmWorkflowControlContext() == null? NoYes::No: NoYes::Yes;


    Workflow::activateFromWorkflowType(this.parmWorkflowTemplateName(), vendtableid,this.parmWorkflowComment(), ActivatingFromWeb);

     smmBusRelTable::setWorkflowState(vendtableid, SPL_SalesMarketStatus::Submitted);
}

Public static SPL_SalesMarApprovalResubmitActionMgr construct()
{
    Return new SPL_SalesMarApprovalResubmitActionMgr();
}

Public static void main(Args _args)
{
    SPL_SalesMarApprovalResubmitActionMgr SPL_SalesMarApprovalResubmitActionMgr;
    smmBusRelTable        smmBusRelTable;
    FormDataSource          vendtableDataSource;

    smmBusRelTable = _args.Record();
    VendtableDataSource = smmBusRelTable.DataSource();

    SPL_SalesMarApprovalResubmitActionMgr = SPL_SalesMarApprovalResubmitActionMgr::construct();

    If (_args.menuItemName() == menuitemActionStr(SPL_SalesMarApprovalResubmitMenuItem))
    {
        SPL_SalesMarApprovalResubmitActionMgr.init(smmBusRelTable.RecId, _args.menuItemName(),
            _args.caller().getActiveWorkflowConfiguration (),
            _args.caller().getActiveWorkflowWorkItem (),
            Null);
    }
    Else
    {
        SPL_SalesMarApprovalResubmitActionMgr.init(
            smmBusRelTable.RecId,
            _args.menuItemName (),
            Null,
            Null,
            _args.caller ());
    }

    If (SPL_SalesMarApprovalResubmitActionMgr.dialogOk())
    {
        If (SPL_SalesMarApprovalResubmitActionMgr.parmSubmit())
        {
            SPL_SalesMarApprovalResubmitActionMgr.submit();
        }
        Else
        {
            SPL_SalesMarApprovalResubmitActionMgr.reSubmit();
        }

        If (vendtableDataSource)
        {
            vendtableDataSource.research(true);
            vendtableDataSource.refresh();
        }

        If (_args.menuItemName() == menuitemActionStr(SPL_SalesMarApprovalResubmitMenuItem))
        {
            _args.caller().updateWorkflowControls();
        }
    }
}


1 comment:

  1. Dear Sir,

    What is The process of work flow in ax 2009
    send me some document @ ipankaj.u@gmail.com

    ReplyDelete