web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Finance | Project Operations, Human Resources, ...
Answered

Using dispatchWorkItemAction to Update Workflow Status to Request Change

(4) ShareShare
ReportReport
Posted on by 441
Hello everyone,
I am creating a custom service API that includes a method called RequestChange(_payload). Inside this method I want to use (WorkflowWorkItemActionManager::dispatchWorkItemAction) to update a workflow work item’s status to Request Change.
I already have the following work item information available in the payload:
 
{
  "_payload": {
    "Id": "6d4d4a1c-e0e2-4173-8ebf-c18f6dd0caf5",
    "MenuItemName": "PurchTable",
    "RefRecId": 5637660841,
    "RefTableId": 27271,
    "TableName": "PurchTable",
    "DocumentNumber": "PO800313",
    "RootCorrelationId": "aaf651f9-61b9-486d-ad8d-10e07eea04h7",
    "outcome": "RequestChange"
  }
}
 
My question is:
When I update the approval status of workflow is it enough or I should update  ApprovalStatus field in the header table for example (PurchTable) I also need to update the approval status in the line tables ? 
Are there any other tables, fields, or additional steps I should consider to ensure the workflow status is updated correctly and avoid mistakes? I want to make sure the workflow engine stays consistent and that no side effects occur from partial updates.
Thanks
 
I have the same question (0)
  • Verified answer
    Sohaib Cheema Profile Picture
    49,438 User Group Leader on at
    No, you do not need to update individual status field of workflow on the subject/record, Once you are approving the subject/record with context RecId and TableId, you are good to go.
     
    It is for the fact, workflow type has completed event handler, which is an x++ class. That updates backs the status.
     
  • D365FO Junior-Dev Profile Picture
    441 on at
    Hi @Sohaib Cheema thnak you very much, I have tested it in RunableClass but under the Action in tracking detail list is Approval it should be (Request change) !!

     
     
     
     
     
     
     
     
     
     
        public static void main(Args _args)
        {
            
            WorkflowWorkItemTable workItem;
            WorkflowComment comment = "Dears, please update the total..";
            WorkflowWorkItemActionType actionType = WorkflowWorkItemActionType::RequestChange;
            MenuItemName menuItem = 'PurchTable';
            Guid _workItemId = str2Guid("6d4d4a1c-e0e2-4173-8ebf-c18f6dd0caf5");
    
            workItem = WorkflowWorkItemTable::find(_workItemId);
    
            if (!workItem.RecId)
            {
                throw error(strFmt("Work item %1 not found.", _workItemId));
            }
            if (workItem.Status != WorkflowWorkItemStatus::Pending)
            {
                throw error("Work item is not pending.");
            }
    
            comment = strFmt("@ApplicationFoundation:ExternalWorkitemCompletionTag", comment);
    
            WorkflowWorkItemActionManager::dispatchWorkItemAction(
        workItem,
        comment,
        workItem.UserId,
        actionType,
        menuItem
    );
    
            info("Request change action completed.");
    
    
    
    
        }
     
  • Suggested answer
    DAnny3211 Profile Picture
    11,397 on at

    Hi there 👋

    Thanks for your question!

    When updating the workflow status using a custom service API like RequestChange(payload), it's important to ensure consistency across all related tables and workflow components to avoid side effects.

    ✅ Here are key considerations:

    1. Update the workflow work item status
      Yes, you should update the status of the workflow work item itself using the appropriate workflow framework methods (e.g., WorkflowWorkItemTable).

    2. Update the header table (e.g., PurchTable)
      If your workflow logic relies on the ApprovalStatus field in PurchTable, you should update it to reflect the new status (RequestChange). This ensures that UI components and reports show the correct status.

    3. Update related line tables if applicable
      If your workflow spans line-level data (e.g., PurchLine), and those lines have their own approval status fields, you should update them as well—especially if business logic or validations depend on it.

    4. Trigger workflow events properly
      Use the workflow runtime APIs to trigger status changes rather than manually updating fields. This ensures that all workflow history, tracking, and notifications are handled correctly.

    5. Audit and history tracking
      Make sure any changes are logged appropriately in workflow history tables (e.g., WorkflowTrackingTable) to maintain traceability.

    6. Test thoroughly
      Always test in a sandbox environment to ensure that the workflow behaves as expected and that no orphaned or inconsistent records are created.

    Hope this helps!
    ✅ Please mark this reply as helpful if it answered your question.
    Best regards! 👋

  • Sohaib Cheema Profile Picture
    49,438 User Group Leader on at
     
    you need pass parameter named workItemActionType correctly. It is a base enum that indicates which action of the workflow you want to take
     
  • Verified answer
    D365FO Junior-Dev Profile Picture
    441 on at
    Hi everyone,

    Thanks for your answers and suggestions. The menuItemAction should be used instead of MenuItemName for example: menuItemActionStr(VendInvoiceApprovalRequestChange)

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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > Finance | Project Operations, Human Resources, AX, GP, SL

#1
Martin Dráb Profile Picture

Martin Dráb 664 Most Valuable Professional

#2
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 522 Super User 2025 Season 2

#3
Sohaib Cheema Profile Picture

Sohaib Cheema 303 User Group Leader

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans