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 :
Microsoft Dynamics AX (Archived)

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

(0) ShareShare
ReportReport
Posted on by 2,162

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

I have the same question (0)
  • MYGz Profile Picture
    2,162 on at

    Thanks Crispin,

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

  • MYGz Profile Picture
    2,162 on at

    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,162 on at

    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?

  • Verified answer
    MYGz Profile Picture
    2,162 on at

    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.

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 > 🔒一 Microsoft Dynamics AX (Archived)

#1
Priya_K Profile Picture

Priya_K 4

#1
Martin Dráb Profile Picture

Martin Dráb 4 Most Valuable Professional

#3
Ali Zaidi Profile Picture

Ali Zaidi 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans