Skip to main content

Notifications

Community site session details

Community site session details

Session Id :
Microsoft Dynamics AX (Archived)

Workflow approval with X++. Element outcome is not defined on the workflow element.

(0) ShareShare
ReportReport
Posted on by 2,042

Hi,

I have a workflow set on Accounts Payable Payment Journal. The workflow has 2 stages. 1st stage is approved.

I want to approve the 2nd stage (Also I'd like to know how to approve on only 1 stage at time or both stages together)

Here's my code:

static void Job61(Args _args)
{
    LedgerJournalTable ljt;
    LedgerJournalCheckPost post;
    WorkflowWorkItemTable workflowWorkItemTable;

    while select ljt where ljt.JournalNum=='XYZ-001'
    {

       while select workflowWorkItemTable where
            (workflowWorkItemTable.Type == WorkflowWorkItemType::WorkItem) &&
            (workflowWorkItemTable.Status == WorkflowWorkItemStatus::pending) &&
            workflowWorkItemTable.RefRecId == ljt.RecId &&
            workflowWorkItemTable.RefTableId == ljt.TableId
        {
            info(int642str(workflowWorkItemTable.RecId));
            
          WorkflowWorkItemActionManager::dispatchWorkItemAction(
                                workflowWorkItemTable,
                                "Approved via X++ on Mr. ABC's Request",
                                curUserId(),
                                WorkflowWorkItemActionType::Complete,
                                "LedgerJournalTable5",
                                false);
        }

    }
}


I'm getting this error on running it:

4034.WorkFlowError.png

I also tried changing 

'LedgerJournalTable5' to 'WorkflowConfigurationVend'

Right clicking and personalizing the workflow:

1781.WorkFlowError2.png

Any tips appreciated.

*This post is locked for comments

  • Verified answer
    MYGz Profile Picture
    2,042 on at
    RE: Workflow approval with X++. Element outcome is not defined on the workflow element.

    Hi Crispin,

    Thanks for you tips.

    This was the first time I dealt with workflow from Code. So wasn't aware about the structure.

    My mistake was, I was giving the wrong menu-item name in the code in Original Post, after fixing, it worked perfect, I didn't had to make any other changes whatsoever. First I tried 'LedgerJournalTable5' which is a form name, then I right clicked on workflow in workflow list page and got 'WorkflowConfigurationVend' which was also wrong.

    The correct menu item name was obtained from AOT > Workflow > Approvals > VendDisbursementApproval > Outcomes > Approve

    which is 'PaymVendDisbWFApprApprove'

    Since my workflow steps have single approver, here's the final code:

    static void Job61(Args _args)
    {
        LedgerJournalTable ljt;
        WorkflowWorkItemTable workflowWorkItemTable;
    while select ljt where ljt.JournalNum == 'Your Condition' {
    // firstonly for Single Approver while select firstOnly workflowWorkItemTable where (workflowWorkItemTable.Type == WorkflowWorkItemType::WorkItem) && (workflowWorkItemTable.Status == WorkflowWorkItemStatus::Pending) && workflowWorkItemTable.RefRecId == ljt.RecId && workflowWorkItemTable.RefTableId == ljt.TableId { WorkflowWorkItemActionManager::dispatchWorkItemAction( workflowWorkItemTable, "Approved via X++ on Mr. ABC's Request", curUserId(), WorkflowWorkItemActionType::Complete, "PaymVendDisbWFApprApprove", false); } } }

    NOTE!!!:

    After running this Job, we have to wait for some time (~1-2 mins, depends) before you can see the change in the WorkFlow history tracking details:

    I didn't wait earlier and thought my Job was not working so I ran it multiple times which resulted into Approving multiple times with multiple assignees even though it has a SINGLE APPROVER setting.

  • MYGz Profile Picture
    2,042 on at
    RE: Workflow approval with X++. Element outcome is not defined on the workflow element.

    Do you think I should add something like this to the completed method? Will have to replace salestable with ledgerjournaltable/trans

    completed(WorkflowEventArgs _workflowEventArgs)
    {
       SalesTable SalesTable;
    
       ttsbegin;
       select forupdate SalesTable 
    		where SalesTable.RecId == _workflowEventArgs.parmWorkflowContext().parmRecId();
    
        if (salesTable.CreditLimitApprovalStatus == SalesCreditLimitApprovalStatus::Submitted)
        {
    		SalesTable.CreditLimitApprovalStatus = SalesCreditLimitApprovalStatus::Approved;
            SalesTable.update();
        }
       ttscommit;
    }

    I got this code from here:

    [View:https://ax2012anant.blogspot.com/2014/01/workflow-in-ax-2012-complete.html?m=1:750:50]

    Can you suggest some good technical resource to study the workflow design architecture?

  • MYGz Profile Picture
    2,042 on at
    RE: Workflow approval with X++. Element outcome is not defined on the workflow element.

    I didn't find anything relevant in AOT > WorkFlow > Tasks > ...

    But I found in AOT > WorkFlow > Approvals > VendDisbursementApproval

    1

    15787.4.png

    2

    06878.2.png

    3A

    0815.3.png

    3B

    15787.4.png

    3B_Completed

    8304.5.png

    LedgerJournalWFApprEventHandlerElem.Completed() is empty while it's other methods do have code.

  • MYGz Profile Picture
    2,042 on at
    RE: Workflow approval with X++. Element outcome is not defined on the workflow element.

    Thanks Crispin,

    Can you explain what you mean by "so select the menu item again"?

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

Jainam Kothari – Community Spotlight

We are honored to recognize Jainam Kothari as our June 2025 Community…

Congratulations to the May Top 10 Community Leaders!

These are the community rock stars!

Announcing the Engage with the Community forum!

This forum is your space to connect, share, and grow!

Leaderboard > 🔒一 Microsoft Dynamics AX (Archived)

#1
Mohamed Amine Mahmoudi Profile Picture

Mohamed Amine Mahmoudi 100 Super User 2025 Season 1

#2
Community Member Profile Picture

Community Member 50

#3
shanawaz davood basha Profile Picture

shanawaz davood basha 6

Featured topics

Product updates

Dynamics 365 release plans