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

Announcements

No record found.

News and Announcements icon
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 56

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!

I have the same question (1)
  • @rp@n Profile Picture
    56 on at

    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!

  • Zain Bokhari Profile Picture
    3,208 Moderator on at

    What is the error you get? 

  • @rp@n Profile Picture
    56 on at

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

  • Ludwig Reinhard Profile Picture
    Microsoft Employee on at

    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
    56 on at

    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 

  • @rp@n Profile Picture
    56 on at

    Can any one please provide me the code . 

    Thanks in advance!

    Please give me more shed on this 

  • @rp@n Profile Picture
    56 on at

    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.

  • Suggested answer
    Michal Krejza Profile Picture
    Microsoft Employee on at

    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. 

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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Meet the Microsoft Dynamics 365 Contact Center Champions

We are thrilled to have these Champions in our Community!

Congratulations to the March Top 10 Community Leaders

These are the community rock stars!

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

#1
Giorgio Bonacorsi Profile Picture

Giorgio Bonacorsi 649

#2
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 447 Super User 2026 Season 1

#3
Syed Haris Shah Profile Picture

Syed Haris Shah 242 Super User 2026 Season 1

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans