Uncategorized

Microsoft Dynamics AX2012 R3 hierarchy type Workflow

Problem:

To submit the workflow to the manager of the submitter in purchase requisition in Microsoft Dynamics AX2012 R3 .

Solution:

In Microsoft Dynamics AX2012 R3, workflow has the assignment type as “hierarchy” which allow user to submit the workflow to the respective manager set in the hierarchy of the company as shown:

workflow assignment type :

Main screen

Hierarchy Selection:

stopping condition screen

In my case , i need to submit the workflow to the “manager” and “manager of manager” of the “Requester” of purchase requisition line.

for example:

if “A” is requester of line and its manager is “B” and B’s manager is “C” (A -> B -> C)

so in this scenario the workflow stopping condition will be set to “line manager level” value to “2” but it is compulsory that requester must have the 2 levels of manager.(as shown above)

in the same way if you need to assign to only direct manager than you just need to set the value of “line manager level” to 1. ( A -> B)

but let say if we have any scenario where we need to allow the submitter to directly assign the workflow to the head of the depart (C), to achieve this part we need to set the line manager level to 2 but also set the user assignment to “Assign only to last user retrived” as shown below ( A -> C) :

asignment condition screen

In my case I need to assign to ( A -> B -> C) that’s why it is set to “Assign to all user retrieved”

Problems faced:

  1. User must have the relation set in the System administration/Common/Users/Users -> Relations
  2. Must have the Hierarchy according to the level defined.
  3. To test the user levels I use the following test job to identify the issues:

static void hierachyWorkflow(Args _args)
{
WorkflowTypeName workflowTemplateName = ‘PurchReqLineReview’;

PurchReqLine purchReqLine;
str nodeId = ‘1312’; //worker personal number
WorkflowHierarchyLevel level = 0;
WorkflowContext workflowContext;
SysWorkflowTable workflowTable;
WorkflowLimitHierarchyProvider workflowLimitHierarchyProvider;
WorkflowHierarchyProviderNode workflowHierarchyProviderNode;
HRPWorkerLimit workerLimit = new HRPWorkerLimit();
HcmWorker hcmWorker;
DirPersonUser dirPersonUser;
RefRecId hcmPositionRecId;
HcmPosition hcmPosition;
container spendingCon, approvalCon;
UserId userId;

select firstOnly workflowTable
where workflowTable.TemplateName == workflowTemplateName;

select firstOnly purchReqLine
where purchReqLine.PurchReqTable == 5637149833; // RecId of purch req line

workflowContext = WorkflowContext::newWorkflowContext(
curext(),
tableNum(purchReqLine),
purchReqLine.RecId,
workflowTable.WorkflowCorrelationId);

workflowLimitHierarchyProvider = new WorkflowLimitHierarchyProvider();

//Level 1
while (nodeId && level < 2)
{
workflowHierarchyProviderNode = workflowLimitHierarchyProvider.getNextNode(nodeId, level, workflowContext);
nodeId = workflowHierarchyProviderNode.getnodeId();
hcmWorker = HcmWorker::findByPersonnelNumber(nodeId);
userId = DirPersonUser::findParty(hcmWorker.Person).User;
hcmPositionRecId = HcmWorker::getPrimaryPosition(hcmWorker.RecId);
hcmPosition = HcmPosition::find(hcmPositionRecId);

spendingCon = workerLimit.getWorkerSigningLimit(
hcmWorker.RecId,
SourceDocumentRelationType::ExpenseReport,
HRPLimitType::Spending,
hcmPosition.PositionId);

approvalCon = workerLimit.getWorkerSigningLimit(
hcmWorker.RecId,
SourceDocumentRelationType::ExpenseReport,
HRPLimitType::Approval,
hcmPosition.PositionId);

info(strFmt(“UserId: %1 | WorkerId: %2 | PositionId: %3 | ReportsToPosition: %4 | SpendingLimit: %5 | ApprovalLimit: %6”,
userId,
hcmWorker.PersonnelNumber,
hcmPosition.PositionId,
hcmPosition.reportsToPosition(),
con2Str(spendingCon),
con2Str(approvalCon)
));

level++;
}
}

Happy Daxing with Rizz 😉

 

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s