Creating Workflow for courses in HumanResource Module.
- Create WFstatus enum
- Create query for that table
- Add workflowstate enum as a field in HRMCourseTable
- Override CanSubmittoworkflow() of table with following code
{
boolean ret;
ret = super(_workflowType);
ret = this.RecId != 0 && this.WorkflowState == WorkflowState::NotSubmitted;
return ret;
}
Find some important links for WF approvals
Signing limits in AX 2012
Managerial hierarchy in AX 2012
Approval limits in AX 2012
boolean ret;
ret = super(_workflowType);
ret = this.RecId != 0 && this.WorkflowState == WorkflowState::NotSubmitted;
return ret;
}
- Also write Updateworkflowstate method(Not override)
public static void UpdateWorkflowState(RefRecId _recId, WorkflowState _state)
{
HRMCourseTable hRMCourseTable = hRMCourseTable::findByRecId(_recId, true);
ttsBegin;
hRMCourseTable.WorkflowState = _state;
if(hRMCourseTable.RecId)
hRMCourseTable.update();
ttsCommit;
}
- Create/Identify WF category(module)
- Create WF type from wizard
- Create WF approval from wizard and give appropriate label names to all created MIs
- Private projects will be created.
- In WF Type main() of submitMngr class write as below and make necesary changes
public static void main(Args args)
{
HRMCourseTable hRMCourseTable;
FormRun formRun = args.caller();
recId recId = args.record().RecId;
WorkflowCorrelationId workflowCorrelationId;
WorkflowTypeName workflowTypeName =workflowtypestr(CoursesWFType);
WorkflowComment note ="";
WorkflowSubmitDialog workflowSubmitDialog;
workflowSubmitDialog = WorkflowSubmitDialog::construct(args.caller().getActiveWorkflowConfiguration());
workflowSubmitDialog.run();
if (workflowSubmitDialog.parmIsClosedOK())
{
recId = args.record().RecId;
hRMCourseTable = HRMCourseTable::findByRecId(recId);
//We can validate record before submite and will through error
note = workflowSubmitDialog.parmWorkflowComment();
try
{
ttsbegin;
workflowCorrelationId = Workflow::activateFromWorkflowType(workflowTypeName,recId,note,NoYes::No);
hRMCourseTable::UpdateWorkflowState(recId,WorkflowState::PendingApproval);
info("Submitted to workflow.");
ttscommit;
}
catch(exception::Error)
{
info("Error on workflow activation.");
}
}
formRun.dataSource().research(1);
formRun.reload();
}
- In the WFType Eventhandler write appropriate code in existed methods
public void completed(WorkflowEventArgs _workflowEventArgs)
{
if (_workflowEventArgs.parmWorkflowContext().parmTableId() == tableNum(HRMCourseTable))
HRMCourseTable::UpdateWorkflowState(_workflowEventArgs.parmWorkflowContext().parmRecId(),WorkflowState::Approved);
}
- In WFApproval ResubmitActionManager class, write following
public class CoursesWFApprovalResubmitActionMgr
{
RecId recId;
Args args;
}
protected boolean actionDialog(WorkflowWorkItemActionDialog _workflowWorkItemActionDialog)
{
_workflowWorkItemActionDialog.run();
return _workflowWorkItemActionDialog.parmIsClosedOK();
}
protected WebActionItemName getEPReSubmitAction()
{
WebActionItemName WebActionItemName;
return WebActionItemName;
}
public Args parmArgs(Args _args = args)
{
args = _args;
return args;
}
public boolean reSubmit()
{
WorkflowWorkItemActionDialog workflowWorkItemActionDialog;
WorkflowWorkItemTable workItem = args.caller().getActiveWorkflowWorkItem();
boolean ret;
boolean dispatchWorkItem = false;
WorkflowComment comment;
UserId targetUser;
if (workItem.RecId)
{
workflowWorkItemActionDialog = WorkflowWorkItemActionDialog::construct( workItem,
WorkflowWorkItemActionType::Resubmit,
new MenuFunction(args.menuItemName(), args.menuItemType()));
if (this.actionDialog(workflowWorkItemActionDialog))
{
comment = workflowWorkItemActionDialog.parmWorkflowComment();
targetUser = workflowWorkItemActionDialog.parmTargetUser();
dispatchWorkItem = true;
}
}
if (dispatchWorkItem)
{
WorkflowWorkItemActionManager::dispatchWorkItemAction(workItem,
comment,
targetUser,
WorkflowWorkItemActionType::Resubmit,
args.menuItemName(),
args.menuItemName() == this.getEPReSubmitAction());
ret = true;
}
return ret;
}
public static void main(Args args)
{
CoursesWFApprovalResubmitActionMgr submitManager = new CoursesWFApprovalResubmitActionMgr();
submitManager.parmArgs(args);
submitManager.reSubmit();
}
- Drag WFapproval into WFtype-->supported elements
- Give Form design properties(WorkflowEnabledyes,WorkflowDataSource,WorkflowType)
- Generate Incremental CIL.
- Configure WF
- Double click on approval element
Find some important links for WF approvals
Signing limits in AX 2012
Managerial hierarchy in AX 2012
Approval limits in AX 2012
No comments:
Post a Comment