Skip to main content

Notifications

Community site session details

Community site session details

Session Id :
Finance | Project Operations, Human Resources, ...
Suggested answer

auto submit workflow in purchase order in AX 2012 r3

(0) ShareShare
ReportReport
Posted on by 18

Hi All,

I have created a dialog and added one parameter " Auto submit  workflow". if Auto submit  workflow is enabled yes and run the dialog then it will check each PO , which having staus = open order, approval status = Draft and PO lines, unit price should not be 0. 

If the above  condition is matched then the respective PO should be auto submit.

I wrote  the below code for testing purpose

static void AutoSubmitWorkFlow(Args _args)
{
    RecId       recId;
    
    recId = PurchTable::find("PO-0007929").RecId;
    
    Workflow::activateFromWorkflowType(workFlowTypeStr(PurchTableTemplate), recId,"auto submit to workflow", false, curUserid()); 
    info("done");
}

It successfully executed but not submitted the PO = PO-0007929

8475.j1.jpg

Kindly let me know, if i missed any thing?

Please give me more shed on this.

thanks!

  • Suggested answer
    Michal Krejza Profile Picture
    on at
    RE: auto submit workflow in purchase order in AX 2012 r3

    Hi @rp@n,

    I would recommend to use the standard code used for submitting PO into workflow. If you review the code hidden behind submit button, you will find the answer. 

    Stay safe. 

  • @rp@n Profile Picture
    18 on at
    RE: auto submit workflow in purchase order in AX 2012 r3

    Hi all,

    I have wrote the below code for PO auto submit workflow

    static void POAutoSubmitworkflow(Args _args)
    {
       WorkflowVersionTable  workflowVersionTable;
       PurchTable           _purchTable;
        
       VersioningPurchaseOrder  versioningPurchaseOrder;
       boolean Draft = true;
    
       _purchTable = PurchTable::find("PO-0006371");
    
       workflowVersionTable = Workflow::findWorkflowConfigToActivateForType(
                           workFlowTypeStr(PurchTableTemplate),
                           _purchTable.RecId,
                           _purchTable.TableId);
        
       if (_purchTable.RecId
       && workflowVersionTable.RecId
       && _purchTable.DocumentState == VersioningDocumentState::Draft)
       {
         // for auto workflow submission...
         Workflow::activateFromWorkflowType(
                 workFlowTypeStr(PurchTableTemplate),
                 _purchTable.RecId,
                 "Auto submit to workflow",
                 false,
                 curUserid());       
           
            ttsBegin; 
            purchTable::setWorkflowState(_purchTable.RecId, VersioningDocumentState::InReview);
            ttsCommit;       
           
            info("PO submitted to workflow");
       }
       else
       {
         Draft = false;
       }
    }

    PurchTable - setWorkflowState method - 

    public static void setWorkflowState(RecId                   _purchRecId,
                                        VersioningDocumentState _documentState)
    {
        PurchTable            purchTable;
    
        ttsbegin;
    
        purchTable = PurchTable::findRecId(_purchRecId,true);
        purchTable.DocumentState = _documentState;
    
        switch (_documentState)
        {
            case VersioningDocumentState::InReview:
                purchTable.DocumentState = VersioningDocumentState::InReview;
                break;
            default:
                break;
        }
        purchTable.update();
        ttscommit;
    }

    While update the Inreview status in Purch Table, I got the below error

    4150.d1.jpg

    I have debugged the issue and found the below error coming from 

    3225.j2.jpg

    this.getDocumentState method - 

    4213.j3.jpg

    Why it is taking "InReview" status? ***

    In PurchTable i checked, it is showing Document state = "Draft status"

    3058.t2.jpg

    Kindly give me the solution please.

    waiting for the response.

  • @rp@n Profile Picture
    18 on at
    RE: auto submit workflow in purchase order in AX 2012 r3

    Can any one please provide me the code . 

    Thanks in advance!

    Please give me more shed on this 

  • @rp@n Profile Picture
    18 on at
    RE: auto submit workflow in purchase order in AX 2012 r3

    Hi Ludwig,

    Yes, when I submitted manually the workflow PO, its successfully submitted.  And goes to next level approval.

    No error.

    Is my code is correct? Needs to add something?

    Please give me more shed on this 

  • Ludwig Reinhard Profile Picture
    Microsoft Employee on at
    RE: auto submit workflow in purchase order in AX 2012 r3

    Hi @rp@n, Does the workflow end without error if you remove your code adjustment? Wonder if there is a general problem with this workflow. Best regards, Ludwig

  • @rp@n Profile Picture
    18 on at
    RE: auto submit workflow in purchase order in AX 2012 r3

    Error i not able to find. In notification I saw...

  • Zain Bokhari Profile Picture
    3,208 Moderator on at
    RE: auto submit workflow in purchase order in AX 2012 r3

    What is the error you get? 

  • @rp@n Profile Picture
    18 on at
    RE: auto submit workflow in purchase order in AX 2012 r3

    I have checked in notification, the workflow stopped with error

    3531.p2.jpg

    Kindly let me know, how will solve this? 

    Please give me more shed on this.

    thanks!

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

🌸 Community Spring Festival 2025 Challenge 🌸

WIN Power Platform Community Conference 2025 tickets!

Jonas ”Jones” Melgaard – Community Spotlight

We are honored to recognize Jonas "Jones" Melgaard as our April 2025…

Kudos to the March Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 294,135 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 232,871 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,158 Moderator

Leaderboard

Product updates

Dynamics 365 release plans