Skip to main content

Notifications

Announcements

No record found.

Finance | Project Operations, Human Resources, ...
Suggested answer

How To Get Workflow Approval Action Menu Item Name?

(0) ShareShare
ReportReport
Posted on by 896

Hello dears!

I'm trying to create a grid where it has different records from different datasources.

the grid has the reference table id and reference record id of the records coming from different datasources.

and I am trying to make a short cut for the approval process for the workflow. there is a custom approve button on the grid which once clicked it will approve the work item in the workflow.

using this method:

WorkflowWorkItemActionManager::dispatchWorkItemAction(
workflowWorkItemTable, //Workflow Work item table record
"Approved in custom button!!!", //Comment
curUserId(), //Current user Id
WorkflowWorkItemActionType::Complete, // Approve action type
"PurchLineApprovalApprove");//Action Menu Item Name //This last parameter is where i'm having the issue

I want to make this code as variable as possible, but the last parameter is where I'm having my issue.

I need to get the workflow approve action menu item name through x and not hard code it with a string like what I'm doing in the code above for example: "PurchLineApprovalApprove".

This is a screenshot for where the value I need to get is located:

pastedimage1647179906327v1.png

Because, I'm dealing with custom workflows, and if later someone created a new workflow and assigned the new workflow with a different "action menu item name", the above hard coded code will not work.

also I don't want to use a switch case for the different datasources in the grid. if it's possible to get the value through x , this will reduce the code lines for this task.

is it possible to get the value of the workflow approval "Action Menu Item" property through x knowing the Rec Id and table id of the record?

I was able to locate the workflow and the workflow version for the record using the RecId and TableId of the record.

But is it possible to get the "Approve action menu item" property value?

Sorry for my English and thanks in advance!

  • How To Get Workflow Approval Action Menu Item Name?
    In the workflow section, fill in the fields as described in the following table. 
  • Suggested answer
    Azib Profile Picture
    Azib 5 on at
    RE: How To Get Workflow Approval Action Menu Item Name?

    Hello Momochi,

    Here's what I'm doing: I'm handling work items assigned to me in the power apps, and from there, I'm calling the code below.

    /// workflow actions

    ///

    #define.Approve("Approve")

    #define.Reject("Reject")

    #define.RequestChange("RequestChange")

    WorkflowWorkItem::takeAction(WorkflowWorkItemTable.Id, _action, _comment, curUserId());

  • rakeshtrrk Profile Picture
    rakeshtrrk 5 on at
    RE: How To Get Workflow Approval Action Menu Item Name?

    Hi momochi, did you find how to validate users while using document menu item in workflows?

  • André Arnaud de Calavon Profile Picture
    André Arnaud de Cal... 291,791 Super User 2024 Season 2 on at
    RE: How To Get Workflow Approval Action Menu Item Name?

    Hi Momochi,

    You have to be really careful with customizations in this area. A change might need a validation from external auditors. In this case, you would need to either hide work items which are not assigned to the current user or hide the document menu item.

    You mentioned a reason to have a quicker approval. Does your custom form have enough information to determine the contents of the document that needs to be approved or rejected?

  • Momochi Profile Picture
    Momochi 896 on at
    RE: How To Get Workflow Approval Action Menu Item Name?

    I tried using the document menu item name instead of the approve action name in the method I posted in the original post above.

    WorkflowWorkItemActionManager::dispatchWorkItemAction(
    workflowWorkItemTable, //Workflow Work item table record
    "Approved in custom button!!!", //Comment
    curUserId(), //Current user Id
    WorkflowWorkItemActionType::Complete, // Approve action type
    "PurchTable");//--Updated to Document Menu Item Name instead of approve action menu item

    and it worked. it approved the work item in the workflow.

    and also shockingly, even though this method has a user ID parameter, it approved the work item even though it was assigned to a different user other than the one I am logged in with. and work item said it was approved by the user which was assigned to it, not by my user haha.

    So, now it seems that I don't need the action menu item. and the document menu item name is sufficient, and I can specify the action by specifying it in the actionType parameter in the above method "WorkflowWorkItemActionType::Complete".

    So now I believe I can make it variable by checking the document menu item name of the workflow for the record. 

    But I have to take care now of the user validity to approve the workflow...I was not expecting it to approve something my user was not assigned to.

  • Momochi Profile Picture
    Momochi 896 on at
    RE: How To Get Workflow Approval Action Menu Item Name?

    Hi Gunjan,

    Thanks for your recommendations.

    But I will try to achieve the approval to have a quick big button with a single click.

    How does the ActionMenuItem work? what I see is that the action menu item has an object of WorkflowWorkItemActionManager type and nothing else.

  • Gunjan Bhattachayya Profile Picture
    Gunjan Bhattachayya 35,421 on at
    RE: How To Get Workflow Approval Action Menu Item Name?

    Hi Momochi,

    I think it will be pretty complicated to replicate the workflow features with custom buttons. Using the 'Work items assigned to me' form might be the easiest way to get a shortcut implemented.

    In case you want to show more information on your form regarding the purchase orders (or any other record), you can try following a similar design as in 'Work items assigned to me' form. You will then get all the options - Approve, reject etc. under the Workflow button.

  • Momochi Profile Picture
    Momochi 896 on at
    RE: How To Get Workflow Approval Action Menu Item Name?

    Actually if it's not possible to get the value through x++, it will be complicated since some workflows have 2 to 3 approvals...and I have to try and identify which approval step it is so I can put the correct approval action menu name for the 1st or 2nd or 3rd approval in the switch case 

    And if later the workflows were updated to have more steps, it will not work, the code needs to be updated too. and it will be hard to follow for all different requests from the different datasources....

  • Momochi Profile Picture
    Momochi 896 on at
    RE: How To Get Workflow Approval Action Menu Item Name?

    Hi Andre,

    I am trying to develop a different UI experience and part of that is to have a quick approve/reject buttons. :)

  • Momochi Profile Picture
    Momochi 896 on at
    RE: How To Get Workflow Approval Action Menu Item Name?

    Hi Gunjan,

    Oh, that's unfortunate.

    How I determine user assigned for the record is by using the WorkflowWorkItemTable. I will check the user assigned for this work item. Then enabling and disabling the custom approve/reject buttons based on the assigned user.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Congratulations 2024 Spotlight Honorees

Kudos to all of our 2024 community stars! 🎉

Meet the Top 10 leaders for December

Congratulations to our December super stars! 🥳

Start Your Super User Journey Pt 2

Join the ranks of our community heros! 🦹

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,791 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,488 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Product updates

Dynamics 365 release plans