Work Flow in AX-2012
steps:
Steps:
First create one enum
type (approval state)
One table having(Ex:
WFTable)
Enum field
Submitted by field
Submitted date field
//And one edt field(NA)
Here in that table 5
methods mandatory
1.Find():
public static WFTable find(Name Name, boolean _forupdate
= false)
{
WFTable WFTable;//
leaveRequests;
;
WFTable.selectForUpdate(_forupdate);
if(Name)
{
select WFTable
where WFTable.Name ==
Name;
}
return WFTable;
}
2.findRecId():
static WFTable findRecId(RecId _recId,
boolean
_forUpdate = false)
{
WFTable WFTable;
;
if (_recId)
{
WFTable.selectForUpdate(_forUpdate);
select firstonly WFTable
where WFTable.RecId ==
_recId;
}
return WFTable;
}
3.can submit():
public boolean canSubmit()
{
;
if(this.WFEnabled ==
ApprovalState::NotSubmitted && this.RecId)
return true;
else
return false;
}
4.cansubmittedworkflow():
Display boolean CanSubmitToWorkFlow(str _workflowtype = '')
{
return this.canSubmit();
}
5.UpdateWorkflowState ():
public static void UpdateWorkflowState(RefRecId _recId, ApprovalState _state)
{
WFTable WFTable = WFTable::findRecId(_recId, true);
//Vacations vacations;
ttsBegin;
//if(WFTable.IsWorkflowToBeResubmitted)
// nsgLeaveRequests.IsWorkflowToBeResubmitted = false;
WFTable.WFEnabled = _state;
/*nsgLeaveRequests.update();
//Commented and added by Britto on 16/10/2012
// if(nsgLeaveRequests.WorkflowState == WFDummiesWorkflowState::Approved
&& SystemSetup::find().AutomaticVacationTransfromEP)
if(nsgLeaveRequests.WorkflowState == NSGLeaveReqWorkflowState::ApprovedII )
{
/*
Vacations::CreateFromEPLeaveRequest(nsgLeaveRequests.LeaveRequestId,
nsgLeaveRequests.EmplId,
nsgLeaveRequests.VacationType,
nsgLeaveRequests.LeaveFrom,
nsgLeaveRequests.LeaveTo,
NASVacationInitiateType::FormRequest,
nsgLeaveRequests.Destination);*/
//nsgLeaveRequests.VacationTransId
=Vacations::CreateFromEPLeaveReq(nsgLeaveRequests);
nsgLeaveRequests.Comments += "\n" + "Final Approval"
+"\n" + nsgLeaveRequests.mostRecentComment();
}
if(nsgLeaveRequests.WorkflowState == NSGLeaveReqWorkflowState::ApprovedII )
{
nsgLeaveRequests.Comments += "\n" + "HR Dept Comments"
+"\n" + nsgLeaveRequests.mostRecentComment();
}
if(nsgLeaveRequests.WorkflowState == NSGLeaveReqWorkflowState::Approved )
{
nsgLeaveRequests.Comments += "\n" + "Dept Head Comment"
+"\n" + nsgLeaveRequests.mostRecentComment();
}
*/
WFTable.update();
ttsCommit;
}
Then next Create a
qury and add data sorce as our table
And then create form
and desighn the form
Here in design
properties set this three property as mandatory
(Workflow enabled-yes
Workflow
datsource-ourtable name
Workflow type- our
workflow
type
::this properties are set in last)
And then go to AOT:
1.Create workflow
category- R.C properties – here select module name(in which module ur
working)
2.workflow
type-rc-addins –create workflow type through wizard
Set properties as:
Name- name of workflow
type
Category- name of our
category type
Query- name of query
which u created
Document
Menuitem- name of form or list page menuitem(in which form or list page ur
showing the list page status)
Document web menu item
–NA
Generate menu item
–Rich client
//(no need to give
field groups)
3.approval- rc-addins
–create workflow Approval through wizard
Set properties as:
Name- approval name
Workflow document-
document item name
Document preview field
group-no need to give
Document menu item-
our form or list page menu item name
Document web menu
item- na
Generate menu
item-rich client
Enable deny outcome-na
4. I f we need task
also same R.c-on task-addins – generate task wizard-here also set the propertis
Then drag in
toworkflow type supported items like as approval
Name-name of the task
Workflow document-
document item name
Document preview field
group-no need to give
Document menu item-
our form or list page menu item name
Document web menu
item- na
Generate menu
item-rich client
Then click next above
window opens
Here we add two things
one returned and completed then next click ok
5. Incremental CIL
6. drag the approval
and task(first) to our workflow type supported element
And then
Write code in classes:
WFApprEventHandler():
Classdeclaratio():
class WFApprEventHandler implements
WorkflowElementCanceledEventHandler,
WorkflowElemChangeRequestedEventHandler,
WorkflowElementCompletedEventHandler, WorkflowElementReturnedEventHandler,
WorkflowElementStartedEventHandler, WorkflowElementDeniedEventHandler,
WorkflowWorkItemsCreatedEventHandler
{
}
Canceled():
public void canceled(WorkflowElementEventArgs _workflowElementEventArgs)
{
WFTable::UpdateWorkflowState(_workflowElementEventArgs.parmWorkflowContext().parmRecId(),
ApprovalState::Cancelled);
}
changeRequested():
public void changeRequested(WorkflowElementEventArgs
_workflowElementEventArgs)
{
WFTable::UpdateWorkflowState(_workflowElementEventArgs.parmWorkflowContext().parmRecId(),
ApprovalState::ChangeRequest);
}
Completed():
public void completed(WorkflowElementEventArgs
_workflowElementEventArgs)
{
WFTable::UpdateWorkflowState(_workflowElementEventArgs.parmWorkflowContext().parmRecId(),
ApprovalState::Approved);
}
created ():
public void created(WorkflowWorkItemsEventArgs
_workflowWorkItemsEventArgs)
{
// TODO: Write code to execute once work items are created.
}
denied ():
public void denied(WorkflowElementEventArgs _workflowElementEventArgs)
{
WFTable::UpdateWorkflowState(_workflowElementEventArgs.parmWorkflowContext().parmRecId(),
ApprovalState::Returned);
}
returned ():
public void returned(WorkflowElementEventArgs _workflowElementEventArgs)
{
WFTable::UpdateWorkflowState(_workflowElementEventArgs.parmWorkflowContext().parmRecId(),
ApprovalState::Returned);
}
Started():
public void started(WorkflowElementEventArgs
_workflowElementEventArgs)
{
WFTable::UpdateWorkflowState(_workflowElementEventArgs.parmWorkflowContext().parmRecId(),
ApprovalState::PendingApproval);
}
WFTypeEventHandler():
Classdeclaration():
class WFTypeEventHandler implements
WorkflowCanceledEventHandler, WorkflowCompletedEventHandler,
WorkflowStartedEventHandler
{
}
Canceled():
public void canceled(WorkflowEventArgs _workflowEventArgs)
{
WFTable::UpdateWorkflowState(_workflowEventArgs.parmWorkflowContext().parmRecId(),
ApprovalState::Cancelled);
}
completed ():
public void completed(WorkflowEventArgs _workflowEventArgs)
{
WFTable::UpdateWorkflowState(_workflowEventArgs.parmWorkflowContext().parmRecId(),
ApprovalState::WorkflowCompleted);
}
started ():
public void started(WorkflowEventArgs _workflowEventArgs)
{
WFTable::UpdateWorkflowState(_workflowEventArgs.parmWorkflowContext().parmRecId(),
ApprovalState::Submitted);
}
WFTypeSubmitManager():
Classdeclaration():
public class WFTypeSubmitManager
{
Name
Name;
WFTable
WFTable;
WorkflowVersionTable
workflowConfigurationTable;
WorkflowComment
workflowComment;
boolean
submit;
WorkflowWorkItemTable workflowWorkItemTable;
UserId
userId;
MenuItemName
menuItemName;
WorkflowTypeName
workflowTemplateName;
EPWorkflowControlContext workflowControlContext;
}
dialogOk():
public boolean dialogOk()
{
WorkflowSubmitDialog workflowSubmitDialog;
WorkflowWorkItemActionDialog workflowWorkItemActionDialog;
boolean ok;
;
if (menuItemName
== menuitemactionstr(WFTypeSubmitMenuItem))
{
workflowSubmitDialog = WorkflowSubmitDialog::construct(this.parmWorkflowConfigurationTable());
workflowSubmitDialog.run();
this.parmWorkflowComment(workflowSubmitDialog.parmWorkflowComment());
ok = workflowSubmitDialog.parmIsClosedOK();
}
else if (menuItemName
== menuitemactionstr(WFApprResubmitMenuItem))
{
workflowWorkItemActionDialog =
WorkflowWorkItemActionDialog::construct( workflowWorkItemTable,
WorkflowWorkItemActionType::Resubmit,
new MenuFunction(menuitemactionstr(WFApprResubmitMenuItem),
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.parmWFTable(_documentRecord);
this.parmSubmit(_menuItemName == menuitemactionstr (WFTypeSubmitMenuItem));
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);
}
}
parmMenuItemName():
public MenuItemName parmMenuItemName(MenuItemName _menuItemName =
menuItemName)
{
;
menuItemName = _menuItemName;
return menuItemName;
}
parmSubmit ():
public boolean parmSubmit(boolean _submit = submit)
{
;
submit = _submit;
return submit;
}
parmWFTable():
public WFTable parmWFTable(WFTable _WFTable = WFTable)
{
;
WFTable = _WFTable;
return WFTable;
}
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 WFTable_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);
WFTable_ds = WFTable.dataSource();
WFTable = WFTable::findRecId(WFTable.RecId, true);
WFTable.WFEnabled = ApprovalState::Submitted;
WFTable.doUpdate();
if (WFTable_ds)
{
WFTable_ds.write();
WFTable_ds.refresh();
}
ttscommit;
}
submit():
private void submit()
{
Object WFTable_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(),WFTable.RecId,
this.parmWorkflowComment(),activatingFromWeb, curuserid());
WFTable_ds = WFTable.dataSource();
WFTable = WFTable::findRecId(WFTable.RecId, true);
WFTable.SubBy = curuserid();
// WFTable.SubDate =
utcDateTime2SystemDateTime(DateTimeUtil::utcNow());
WFTable.WFEnabled = ApprovalState::Submitted;
WFTable.doUpdate();
if (WFTable_ds)
{
WFTable_ds.write();
WFTable_ds.reread();
WFTable_ds.refresh();
}
ttsCommit;
}
construct():
public static WFTypeSubmitManager construct()
{
return new WFTypeSubmitManager();
}
Main():
public static void main(Args args)
{
WFTypeSubmitManager WFTypeSubmitManager;
//EmplContract EmplContract;
WFTable WFTable;
// Variable declaration.
recId recId;
WorkflowCorrelationId workflowCorrelationId;
Object
callerDataSource;
// Hardcoded workflow type name
workflowTypeName workflowTypeName = workflowtypestr("WFType");
// 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.
FormDataSource WFTable_ds;
// Workflow Control Context
EPWorkflowControlContext
workflowControlContext;
;
WFTable = args.record();
WFTypeSubmitManager = WFTypeSubmitManager::construct();
if (args.menuItemName()
== menuitemactionstr(WFTypeSubmitMenuItem) ||
args.menuItemName() == menuitemactionstr(WFApprResubmitMenuItem))
{
WFTypeSubmitManager.init(args.record(), args.menuItemName(),
args.caller().getActiveWorkflowConfiguration(),
args.caller().getActiveWorkflowWorkItem(),null);
}
else
{
WFTypeSubmitManager.init(args.record(), args.menuItemName(), null, null, args.caller());
}
if (WFTypeSubmitManager.dialogOk())
{
if (WFTypeSubmitManager.parmSubmit())
{
WFTypeSubmitManager.submit();
}
else
{
WFTypeSubmitManager.reSubmit();
}
if (args.menuItemName()
== menuitemactionstr(WFTypeSubmitMenuItem) ||
args.menuItemName() == menuitemactionstr(WFApprResubmitMenuItem))
args.caller().updateWorkflowControls();
}
if (!webSession())
{
callerDataSource = args.record().dataSource();
if (callerDataSource)
{
callerDataSource.research(true);
}
args.caller().updateWorkflowControls();
}
}
WFTaskEventHandler:
Classdeclaration() :
class DN_ReserveTaskEventHandler implements
WorkflowElementCanceledEventHandler,
WorkflowElemChangeRequestedEventHandler,
WorkflowElementCompletedEventHandler,
WorkflowElementReturnedEventHandler,
WorkflowElementStartedEventHandler, WorkflowElementDeniedEventHandler,
WorkflowWorkItemsCreatedEventHandler
{
}
Canceled();
public void
canceled(WorkflowElementEventArgs _workflowElementEventArgs)
{
/// TODO: Write code
to execute once the workflow is canceled.
}
changeRequested();
public void
changeRequested(WorkflowElementEventArgs _workflowElementEventArgs)
{
/// TODO: Write code
to execute once change is requested for the workflow.
}
Completed():
public void
completed(WorkflowElementEventArgs _workflowElementEventArgs)
{
WFTable::UpdateWorkflowState(_workflowElementEventArgs.parmWorkflowContext().parmRecId(),ApprovalState::TaskCompleted);
}
Created():
public void
created(WorkflowWorkItemsEventArgs _workflowWorkItemsEventArgs)
{
/// TODO: Write code
to execute once work items are created.
}
Denied():
public void
denied(WorkflowElementEventArgs _workflowElementEventArgs)
{
/// TODO: Write code
to execute once the workflow is denied.
}
Returned():
public void
returned(WorkflowElementEventArgs _workflowElementEventArgs)
{
WFTable::UpdateWorkflowState(_workflowElementEventArgs.parmWorkflowContext().parmRecId(),ApprovalState::Returned);
}
Started():
public void
started(WorkflowElementEventArgs _workflowElementEventArgs)
{
WFTable::UpdateWorkflowState(_workflowElementEventArgs.parmWorkflowContext().parmRecId(),ApprovalState::TaskStarted);
}
After that go to the
module where u r working then go to area page-setup-workflow configuration
Click on that
Create new- select
what u crated
Here u create flow
diagram
Here give the
Basic settings
Assignment-user for
task to ur id(only u)
Assignment-user for
approval to approval persons (one r many)
Here we give the
completion policy(for approval)-single approver
Here we give the time
limit for approval(default r check all days)