AX 2012 Create Custom Workflow - D365 FinOps
AX 2012 Create Custom Workflow - D365 FinOps
Purpose:
The purpose of this document is to describe how we can develop a custom workflow template.
Business requirement:
Ability to have approval process for customers. Standard AX does not offer any workflow for
customers approval out-of-the-box.
The following steps must be completed before a workflow can be unit tested.
if (custTable.RecId &&
custTable.MzkWorkflowApprovalStatus ==
MzkCustWFApprovalStatus::NotSubmitted)
{
canSubmit = true;
}
return canSubmit;
}
4. Add a static method on CustTable table to update workflow status. This method will be called
from workflow event handlers and workflow approval event handlers.
static void mzkUpdateWorkflowStatus(RefRecId _recId,
MzkCustWorkflowStatus _status)
{
CustTable custTable;
ttsBegin;
custTable.MzkWorkflowApprovalStatus = _status;
custTable.update();
ttsCommit;
}
◦ Workflow type
◦ Classes
◦ Document class which extends WorkflowDocument.
◦ EventHandler class which gives implementation to handle different workflow events.
◦ SubmitManager class.
◦ Action menu items:
◦ SubmitMenuItem pointing to SubmitManager class.
◦ CancelMenuItem pointing to WorkflowCancelManager class.
◦ WorkflowEnabled – Yes.
◦ WorkflowDatasource – Name of the form datasource, CustTable.
◦ WorkflowType – Name of the custom workflow type created.
_recId = _args.record().RecId;
_workflowTypeName = workFlowTypeStr("MzkCustWorkflowType");
_initialNote = "";
workflowSubmitDialog.run();
if (workflowSubmitDialog.parmIsClosedOK())
{
_recId = _args.record().RecId;
// Get comments from the submit to workflow dialog.
_initialNote = workflowSubmitDialog.parmWorkflowComment();
try
{
ttsbegin;
_workflowCorrelationId = Workflow::activateFromWorkflowType(
_workflowTypeName, _recId, _initialNote, NoYes::No);
ttscommit;
info("Submitted to workflow.");
}
catch(exception::Error)
{
error("Error on workflow activation.");
}
}
}
13. Define approval element event handlers in workflow approval element event handler class.
_workflowWorkItemsEventArgs.parmWorkflowElementEventArgs().parmWorkflowCo
ntext().parmRecId(),
MzkCustWFApprovalStatus::Created);
}
recID = _args.record().RecId;
tableId = _args.record().TableId;
custTable = _args.record();
workItem = _args.caller().getActiveWorkflowWorkItem();
if (workItem.RecId > 0)
{
try
{
workflowWorkItemActionDialog =
WorkflowWorkItemActionDialog::construct(
workItem,
WorkflowWorkItemActionType::Resubmit,
new
MenuFunction(_args.menuItemName(),_args.menuItemType()));
workflowWorkItemActionDialog.run();
if (workflowWorkItemActionDialog.parmIsClosedOK())
{
if (custTable.MzkWorkflowApprovalStatus ==
MzkCustWFApprovalStatus::ChangeRequested)
{
workItem =
_args.caller().getActiveWorkflowWorkItem();
WorkflowWorkItemActionManager::dispatchWorkItemAction(workItem,
workflowWorkItemActionDialog.parmWorkflowComment(),
workflowWorkItemActionDialog.parmTargetUser(),
WorkflowWorkItemActionType::Resubmit,
_args.menuItemName(),
false);
custTable.MzkWorkflowApprovalStatus
= MzkCustWFApprovalStatus::Submitted;
ttsbegin;
custTable.dataSource().write();
ttscommit;
}
else
{
throw Exception::Error;
}
}
}
catch(Exception::Error)
{
throw error(strfmt("Cannot resubmit workflow."));
}
}
_args.caller().updateWorkflowControls();
}
Published by muhammadanaskhan
1. manali
says:
January 21, 2016 at 3:29 pm
Hi,
I am having requirement about workflow that Employee Transfer is standard workflow
but when i am a�ching some conditions to workflow those customised field like
Department,Branch,Counter is not in those condition.
Thanks,
Manali
1. muhammadanaskhan
says:
January 22, 2016 at 4:41 pm
Hi Manali,
2. Taskheer
says:
March 28, 2017 at 6:07 pm
Submit Bu�on is coming but after clicjing its remain the same and not going for approval,,
Please help.
1. muhammadanaskhan
says:
April 1, 2017 at 9:07 am
Have you implemented the business logic in the *SubmitManager class?
3. Taskheer
says:
April 2, 2017 at 10:37 am
I wri�en the following code in the submit method
TestExpenseTable testexpense;
WorkflowComment note=””;
WorkflowSubmitDialog workflowSubmitDialog;
workflowSubmitDialog =
WorkflowSubmitDialog::construct(_args.caller().getActiveWorkflowConfiguration());
workflowSubmitDialog.run();
if (workflowSubmitDialog.parmIsClosedOK())
{
testexpense = _args.record();
// Get comments from the submit to workflow dialog.
note = workflowSubmitDialog.parmWorkflowComment();
try
{
�sbegin;
testexpense.TestExpensestatus = TestExpensestatus::submit;
�scommit;
// Send an Infolog message.
info(“Submi�ed to workflow.”);
}
catch (Exception::Error)
{
error(“Error on workflow activation.”);
}
}
_args.caller().updateWorkFlowControls();
4. Taskheer
says:
April 2, 2017 at 10:39 am
I wri�en the following code in the submit method
TestExpenseTable testexpense;
WorkflowComment note=””;
WorkflowSubmitDialog workflowSubmitDialog;
workflowSubmitDialog =
WorkflowSubmitDialog::construct(_args.caller().getActiveWorkflowConfiguration());
workflowSubmitDialog.run();
if (workflowSubmitDialog.parmIsClosedOK())
{
testexpense = _args.record();
// Get comments from the submit to workflow dialog.
note = workflowSubmitDialog.parmWorkflowComment();
try
{
�sbegin;
testexpense.TestExpensestatus = TestExpensestatus::submit;
�scommit;
// Send an Infolog message.
info(“Submi�ed to workflow.”);
}
catch (Exception::Error)
{
error(“Error on workflow activation.”);
}
}
_args.caller().updateWorkFlowControls();
5. Tom
says:
April 22, 2017 at 9:33 pm
Hello. Have you worked up a version of this for AX7 (D365 for Operations)?
6. dynamicsoperations
says:
June 17, 2017 at 10:44 am
HI Mr . Muhammad Anas Khan,
Thanks for the post,
11. Drag the newly created approval to the Supported elements node of the custom
workflow type.
I am failing at this point and unable to drag and drop approval type into Workflow type
supported elements,
Can you please suggest the possibilities of this issue.
Environment : D 365.
7. yassine
says:
March 10, 2018 at 7:37 pm
Hi Muhammad Anas Khan,
Thanks for the post,
I have block in the workflow creation part
1. Create a workflow status Enum to have the following elements:
in which location in ax I find that
BLOG AT WORDPRESS.COM.
UP ↑