Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics AX forum
Answered

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

Posted on by 1,794

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.

  • Verified answer
    MYGz Profile Picture
    MYGz 1,794 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
    MYGz 1,794 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
    MYGz 1,794 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
    MYGz 1,794 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"?

Helpful resources

Quick Links

Can you answer this forum question?

You could make someone's day!

Community Newsletter - May 2024

Kudos to our community stars!

Community Spotlight of the Month

Kudos to Mohamed Amine Mahmoudi!

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 283,632 Super User

#2
Martin Dráb Profile Picture

Martin Dráb 224,528 Super User

#3
nmaenpaa Profile Picture

nmaenpaa 101,146

Featured topics

Product updates

Dynamics 365 release plans