Tuesday, 23 July 2013

Workflow Example:

Display boolean CanSubmitToWorkFlow(str _workflow ="")
{
 return this.canSubmit();
}


public boolean canSubmit()
{
    String30    LoanProfile;
    HcmWorker           hcmWorker;
    real                TotalEOSCompensation;
    str                 Msg;
    HcmPersonnelNumberId emplID;
    boolean ret = true;
    real loanDeductvalue;
    real salaryPercentage;
    DialogButton    _dlgBtn;
    ;

    if(this.AssetApprovalState == ApprovalState::NotSubmitted  && this.RecId && ret)
        return true;
    else
        return false;
}


public static void UpdateWorkflowState(RefRecId _recId, ApprovalState _state)
    {
        AssetTable AssetTable = AssetTable::findByRecId(_recId, true);

        ttsBegin;

        AssetTable.AssetApprovalState = _state;
        AssetTable.update();

        ttsCommit;

   }


static AssetTable findByRecId(RecId recId, boolean update = false)
{
    AssetTable  documentField;
    ;

    documentField.selectForUpdate(update);

    if (recId)
    {
        select firstonly documentField
            where documentField.RecId == recId;
    }

    return documentField;
}

AssetTableApprEventHandler:
Class declaration:

class AssetTableApprEventHandler implements    WorkflowElementCanceledEventHandler,  WorkflowElemChangeRequestedEventHandler,
                                                        WorkflowElementCompletedEventHandler, WorkflowElementReturnedEventHandler,
                                                        WorkflowElementStartedEventHandler, WorkflowElementDeniedEventHandler,
                                                        WorkflowWorkItemsCreatedEventHandler
{
}

Canceled:
public void canceled(WorkflowElementEventArgs _workflowElementEventArgs)
{
    AssetTable::UpdateWorkflowState(_workflowElementEventArgs.parmWorkflowContext().parmRecId(), ApprovalState::NotSubmitted);
}

Changerequest:
public void changeRequested(WorkflowElementEventArgs _workflowElementEventArgs)
{
    AssetTable::UpdateWorkflowState(_workflowElementEventArgs.parmWorkflowContext().parmRecId(), ApprovalState::ChangeRequest);
}


Completed:


public void completed(WorkflowElementEventArgs _workflowElementEventArgs)
{
    AssetTable::UpdateWorkflowState(_workflowElementEventArgs.parmWorkflowContext().parmRecId(), ApprovalState::Approved);
}


Returned:

public void returned(WorkflowElementEventArgs _workflowElementEventArgs)
{
   AssetTable::UpdateWorkflowState(_workflowElementEventArgs.parmWorkflowContext().parmRecId(), ApprovalState::Returned);
}


Started:

public void started(WorkflowElementEventArgs _workflowElementEventArgs)
{
    AssetTable::UpdateWorkflowState(_workflowElementEventArgs.parmWorkflowContext().parmRecId(), ApprovalState::PendingApproval);
}



AssetTableWFTypeEventHandler

Classdeclaration:
class AssetTableWFTypeEventHandler implements    WorkflowCanceledEventHandler,  WorkflowCompletedEventHandler,
                                                        WorkflowStartedEventHandler
{
}


Canceled:

public void canceled(WorkflowEventArgs _workflowEventArgs)
{
    AssetTable::UpdateWorkflowState(_workflowEventArgs.parmWorkflowContext().parmRecId(), ApprovalState::NotSubmitted);
}

Completed:

public void completed(WorkflowEventArgs _workflowEventArgs)
{
    AssetTable::UpdateWorkflowState(_workflowEventArgs.parmWorkflowContext().parmRecId(), ApprovalState::WorkflowCompleted);
}


Started:


public void started(WorkflowEventArgs _workflowEventArgs)
{
    AssetTable::UpdateWorkflowState(_workflowEventArgs.parmWorkflowContext().parmRecId(), ApprovalState::Submitted);
}





AssetTableWFTypeSubmitManager:

Classdeclaration:
public class AssetTableWFTypeSubmitManager
{
    WorkflowVersionTable        workflowConfigurationTable;
    WorkflowComment             workflowComment;
    boolean                     submit;
    WorkflowWorkItemTable       workflowWorkItemTable;
    UserId                      userId;
    MenuItemName                menuItemName;
    WorkflowTypeName            workflowTemplateName;
    EPWorkflowControlContext    workflowControlContext;
    AssetTable                  AssetTable;
}
dialogOk:


public boolean dialogOk()
{
    WorkflowSubmitDialog workflowSubmitDialog;
    WorkflowWorkItemActionDialog workflowWorkItemActionDialog;

    boolean ok;
    ;
    if (menuItemName == menuitemactionstr(AssetTableWFTypeSubmitMenuItem))
    {
        workflowSubmitDialog = WorkflowSubmitDialog::construct(this.parmWorkflowConfigurationTable());
        workflowSubmitDialog.run();
        this.parmWorkflowComment(workflowSubmitDialog.parmWorkflowComment());
        ok = workflowSubmitDialog.parmIsClosedOK();
    }
    else if (menuItemName == menuitemactionstr(AssetTableApprResubmitMenuItem))
    {
        workflowWorkItemActionDialog = WorkflowWorkItemActionDialog::construct( workflowWorkItemTable,
        WorkflowWorkItemActionType::Resubmit,
        new MenuFunction(menuitemactionstr(AssetTableApprResubmitMenuItem), MenuItemType::Action));
        workflowWorkItemActionDialog.run();
        this.parmWorkflowComment(workflowWorkItemActionDialog.parmWorkflowComment());
        ok = workflowWorkItemActionDialog.parmIsClosedOK();
        userId = workflowWorkItemActionDialog.parmTargetUser();
    }

    return ok;
}


Init:


public void init( Common _documentRecord,
                    MenuItemName _menuItemName,
                    WorkflowVersionTable _workflowConfigurationTable,
                    WorkflowWorkItemTable _workflowWorkItemTable,
                    EPWorkflowControlContext _workflowControlContext
                    )
{
    this.parmAssetTable(_documentRecord);
    this.parmSubmit(_menuItemName == menuitemactionstr (AssetTableWFTypeSubmitMenuItem));
    this.parmMenuItemName(_menuItemName);
    if (_workflowControlContext)
    {
        this.parmWorkflowControlContext(_workflowControlContext);
        this.parmWorkflowWorkItemtable (_workflowControlContext.getActiveWorkflowWorkItem());
        this.parmWorkflowComment(_workflowControlContext.getWorkflowComment());
        this.parmWorkflowTemplateName (_workflowControlContext.getActiveWorkflowConfiguration().WorkflowTable().TemplateName);
    }
    else
    {
        this.parmWorkflowConfigurationTable(_workflowConfigurationTable);
        this.parmWorkflowWorkItemtable(_workflowWorkItemTable);
        this.parmWorkflowTemplateName (this.parmWorkflowConfigurationTable().WorkflowTable().TemplateName);
    }


}






parmAssetTable:

public AssetTable parmAssetTable(AssetTable _AssetTable = AssetTable)
{
;
AssetTable = _AssetTable;
return AssetTable;
}


parmMenuItemName:


public MenuItemName parmMenuItemName(MenuItemName _menuItemName = menuItemName)
{
    ;
    menuItemName = _menuItemName;
    return menuItemName;
}

parmSubmit:

public boolean parmSubmit(boolean _submit = submit)
{
;
submit = _submit;
return submit;
}

parmWorkflowComment:


public WorkflowComment parmWorkflowComment(WorkflowComment _workflowComment = workflowComment)
{
;
workflowComment = _workflowComment;
return workflowComment;
}

parmWorkflowConfigurationTable:


public WorkflowVersionTable parmWorkflowConfigurationTable(WorkflowVersionTable _workflowConfigurationTable = workflowConfigurationTable)
{
;
workflowConfigurationTable = _workflowConfigurationTable;
return workflowConfigurationTable;
}

parmWorkflowControlContext:


public EPWorkflowControlContext parmWorkflowControlContext(EPWorkflowControlContext _workflowControlContext = workflowControlContext)
{
;
workflowControlContext = _workflowControlContext;
return workflowControlContext;
}

parmWorkflowTemplateName:







public WorkflowTypeName parmWorkflowTemplateName(WorkflowTypeName _workflowTemplateName = workflowTemplateName)
{
;
workflowTemplateName = _workflowTemplateName;
return workflowTemplateName;
}

parmWorkflowWorkItemtable:


public WorkflowWorkItemTable parmWorkflowWorkItemtable(WorkflowWorkItemTable _workflowWorkItemTable = workflowWorkItemTable)
{
;
workflowWorkItemTable = _workflowWorkItemTable;
return workflowWorkItemTable;
}

resubmit:


private void reSubmit()
{
    Object AssetTable_ds;
    NoYes                   reSubmittingFromWeb;

    // If we have a workflow control context, we are being resubmitted from EP
    reSubmittingFromWeb = this.parmWorkflowControlContext() == null ? NoYes::No : NoYes::Yes;
    ttsbegin;

    WorkflowWorkItemActionManager::dispatchWorkItemAction( workflowWorkItemTable, workflowComment, userId, WorkflowWorkItemActionType::Resubmit, menuItemName, false);
    AssetTable_ds = AssetTable.dataSource();
    AssetTable = AssetTable::findByLedgerDimension(AssetTable.RecId, true);

    AssetTable.AssetApprovalState = ApprovalState::Submitted;
    AssetTable.doUpdate();
    if (AssetTable_ds)
    {
        AssetTable_ds.write();
        AssetTable_ds.refresh();
    }
    ttscommit;
}


Submit:

private void submit()
{
    Object AssetTable_ds;
    NoYes activatingFromWeb;
    ;
    // If we have a workflow control context, we are being activated from EP
    activatingFromWeb = this.parmWorkflowControlContext() == null ? NoYes::No : NoYes::Yes;

    ttsBegin;
    Workflow::activateFromWorkflowType( this.parmWorkflowTemplateName(),AssetTable.RecId, this.parmWorkflowComment(),activatingFromWeb, curuserid());
    AssetTable_ds = AssetTable.dataSource();
    AssetTable = AssetTable::findByRecId(AssetTable.RecId, true);
    //AssetTable.Submittedby = curuserid();
   // NSGLoansRequests.SubmittedDateTime = DateTimeUtil::utcNow();
    AssetTable.AssetApprovalState = ApprovalState::Submitted;
    AssetTable.doUpdate();
    if (AssetTable_ds)
    {
        AssetTable_ds.write();
        AssetTable_ds.reread();
        AssetTable_ds.refresh();
    }
    ttsCommit;
}



Construct:



public static AssetTableWFTypeSubmitManager construct()
{
return new AssetTableWFTypeSubmitManager();
}









Main:


public static void main(Args args)
{
    AssetTableWFTypeSubmitManager AssetTableWFTypeSubmitManager;
    //EmplContract EmplContract;
    AssetTable           AssetTable;
     // Variable declaration.
    recId recId;
    WorkflowCorrelationId workflowCorrelationId;
    Object                          callerDataSource;

    // Hardcoded workflow type name
    workflowTypeName workflowTypeName = workflowtypestr("AssetTableWFType");

    // Initial note is the information that users enter when they
    // submit the document for workflow.
    WorkflowComment initialNote = "Enter any comments here.";
    WorkflowSubmitDialog workflowSubmitDialog;

    // The name of the table containing the records for workflow.
    AssetTable fcmworkOrders;
    FormDataSource   AssetTable_ds;

    // Workflow Control Context
    EPWorkflowControlContext workflowControlContext;

    ;
    AssetTable = args.record();
    AssetTableWFTypeSubmitManager = AssetTableWFTypeSubmitManager::construct();
    if (args.menuItemName() == menuitemactionstr(AssetTableWFTypeSubmitMenuItem) ||
        args.menuItemName() == menuitemactionstr(AssetTableApprResubmitMenuItem))
    {
        AssetTableWFTypeSubmitManager.init(args.record(), args.menuItemName(), args.caller().getActiveWorkflowConfiguration(), args.caller().getActiveWorkflowWorkItem(), null);
    }
    else
    {
        AssetTableWFTypeSubmitManager.init(args.record(), args.menuItemName(), null, null, args.caller());
    }

    if (AssetTableWFTypeSubmitManager.dialogOk())
    {
            if (AssetTableWFTypeSubmitManager.parmSubmit())
            {
                AssetTableWFTypeSubmitManager.submit();
            }
            else
            {
                AssetTableWFTypeSubmitManager.reSubmit();
            }

            if (args.menuItemName() == menuitemactionstr(AssetTableWFTypeSubmitMenuItem) ||
                args.menuItemName() == menuitemactionstr(AssetTableApprResubmitMenuItem))
                    args.caller().updateWorkflowControls();
    }



    if (!webSession())
    {
        callerDataSource = args.record().dataSource();
        if (callerDataSource)
        {
            callerDataSource.research(true);
        }

        args.caller().updateWorkflowControls();
    }

}

No comments:

Post a Comment