Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Finance | Project Operations, Human Resources, ...
Answered

You cannot request a change, because the document is in state Draft. when auto submit the workflow in ax 2012 r3

(0) ShareShare
ReportReport
Posted on by 6

hi Team,

I have wrote code for PO auto Submit

PurchLine   purchOrderLine;

    select purchOrderLine
        where purchOrderLine.PurchId == _purchTable.PurchId
        &&    purchOrderLine.PurchPrice == 0;

    if(!purchOrderLine.RecId && _purchTable.ChangeRequestRequired == NoYes::Yes)
    {
        VersioningPurchaseOrder::newPurchaseOrder(_purchTable).createChangeRequest();
        //_purchTable.ChangeRequestRequired = NoYes::No;
        //_purchTable.doUpdate();

        _purchTable.submitToWorkflow(workFlowTypeStr(PurchTableTemplate),
                                    strFmt("Auto submit by %1",curUserId()),
                                    false);

VersioningPurchaseOrder::newPurchaseOrder(_purchTable).createChangeRequest();

When I used the above code then got below error

0654.E1.jpg

2

PurchLine   purchOrderLine;

    select purchOrderLine
        where purchOrderLine.PurchId == _purchTable.PurchId
        &&    purchOrderLine.PurchPrice == 0;

    if(!purchOrderLine.RecId && _purchTable.ChangeRequestRequired == NoYes::Yes)
    {
        //VersioningPurchaseOrder::newPurchaseOrder(_purchTable).createChangeRequest();
        _purchTable.ChangeRequestRequired = NoYes::No;
        _purchTable.doUpdate();

        _purchTable.submitToWorkflow(workFlowTypeStr(PurchTableTemplate),
                                    strFmt("Auto submit by %1",curUserId()),
                                    false);
    }

If i used,

_purchTable.ChangeRequestRequired = NoYes::No;
_purchTable.doUpdate(); 

*** instead of VersioningPurchaseOrder::newPurchaseOrder(_purchTable).createChangeRequest();

then it is successfully submitted.

Can you please let me know is there any difference between both code  ??

VersioningPurchaseOrder::newPurchaseOrder(_purchTable).createChangeRequest();  

_purchTable.ChangeRequestRequired = NoYes::No;

Please give me more shewd on this.

thanks!

  • @rp@n Profile Picture
    6 on at
    RE: You cannot request a change, because the document is in state Draft. when auto submit the workflow in ax 2012 r3

    Hi Danilo,

    Now it is working fine. Thanks a lot.

    Can you please let me know one more thing. 

    How I will identified, which user submitting the workflow?

    I passed as a parameter curUserId (). As workflow is running in batch. Shall I identified the user ,who submitting the workflow ?

    Please give me more shed on this 

  • Verified answer
    greengrimms Profile Picture
    1,400 on at
    RE: You cannot request a change, because the document is in state Draft. when auto submit the workflow in ax 2012 r3

    So since you're requesting the document state change on the workflow submition method, it should work if you just keep this:

    PurchLine               purchOrderLine;
        VersioningPurchaseOrder versioningPurchaseOrder;
    
        select purchOrderLine
            where purchOrderLine.PurchId == _purchTable.PurchId
            &&    purchOrderLine.PurchPrice == 0;
    
        if(!purchOrderLine.RecId && _purchTable.ChangeRequestRequired == NoYes::Yes
        && _purchTable.DocumentState == VersioningDocumentState::Draft)
        {
            _purchTable.submitToWorkflow(workFlowTypeStr(PurchTableTemplate),
                                        strFmt("Auto submit by %1",curUserId()),
                                        false);
        }

    Have you already try this?

    I'm away from my machine right now so I'm unable to test this, but I think it should work given what we know already.

  • @rp@n Profile Picture
    6 on at
    RE: You cannot request a change, because the document is in state Draft. when auto submit the workflow in ax 2012 r3

    Hi Danilo,

    I found the cause , why this error is coming

    In method - SubmitToWorkflow()

    public void  submitToWorkflow(WorkflowTypeName	     _workflowTemplateName,
                                  WorkflowComment       _workflowComment,
                                  boolean               _activatingFromWeb = false)
    {
        ttsbegin;
    
        Workflow::activateFromWorkflowType(_workflowTemplateName,
                                               this.RecId,
                                               _workflowComment,
                                               _activatingFromWeb,
                                               curUserId());
    
        VersioningPurchaseOrder::newPurchaseOrder(this).submitChangeRequest();
    
        ttscommit;
    }

    Again it is called the class

    VersioningPurchaseOrder::newPurchaseOrder(this).submitChangeRequest();

    Now it is getting DocumentState = INREVIEW

    Due to this I am getting the error

    Please let me know how i will resolve this.?

  • @rp@n Profile Picture
    6 on at
    RE: You cannot request a change, because the document is in state Draft. when auto submit the workflow in ax 2012 r3

    Hi Danilo,

    The PO status is now DRAFT then why the below code executed and getting  error 

    public void submitChangeRequest()
    {
        ttsbegin;
    
        if (this.getDocumentState() != VersioningDocumentState::Draft)
        {
            // Only a document in state Draft can be submitted for approval.
            throw error("@SYS326422");
        }
        this.setDocumentState(VersioningDocumentState::InReview);
    
        ttscommit;
    }

    Even i observed, the code is not go inside if loop. it directly come to this.setDocumentState(VersioningDocumentState::InReview);

    but still getting the error...

    please give me more shed on this

    thanks!

  • @rp@n Profile Picture
    6 on at
    RE: You cannot request a change, because the document is in state Draft. when auto submit the workflow in ax 2012 r3

    Hi Danilo,

    Now I am getting this error

    6646.e2.jpg

    Please give me more shed on this.

    thanks!

  • @rp@n Profile Picture
    6 on at
    RE: You cannot request a change, because the document is in state Draft. when auto submit the workflow in ax 2012 r3

    Thanks a lot

    PurchLine               purchOrderLine;
        VersioningPurchaseOrder versioningPurchaseOrder;
    
        select purchOrderLine
            where purchOrderLine.PurchId == _purchTable.PurchId
            &&    purchOrderLine.PurchPrice == 0;
    
        if(!purchOrderLine.RecId && _purchTable.ChangeRequestRequired == NoYes::Yes
        && _purchTable.DocumentState == VersioningDocumentState::Draft)
        {
                //VersioningPurchaseOrder::newPurchaseOrder(_purchTable).createChangeRequest();
    
                // Versioning: approve change request
                versioningPurchaseOrder = VersioningPurchaseOrder::newPurchaseOrder(_purchTable);
                versioningPurchaseOrder.submitChangeRequest();
                versioningPurchaseOrder.approveChangeRequest();
    
            _purchTable.submitToWorkflow(workFlowTypeStr(PurchTableTemplate),
                                        strFmt("Auto submit by %1",curUserId()),
                                        false);
        }

    Is it correct now?

    Please give me more shed on this

    thanks!

  • Suggested answer
    greengrimms Profile Picture
    1,400 on at
    RE: You cannot request a change, because the document is in state Draft. when auto submit the workflow in ax 2012 r3

    You could replace the createChangeRequest() code for this:

    if (purchTable.DocumentState == VersioningDocumentState::Draft)
    {
        // Versioning: approve change request
        versioningPurchaseOrder = VersioningPurchaseOrder::newPurchaseOrder(purchTable);
        versioningPurchaseOrder.submitChangeRequest();
        versioningPurchaseOrder.approveChangeRequest();
    }

  • @rp@n Profile Picture
    6 on at
    RE: You cannot request a change, because the document is in state Draft. when auto submit the workflow in ax 2012 r3

    hi Danilo,

    thanks for prompt response

    Can you please let me know how i will achieve this with the code

    VersioningPurchaseOrder::newPurchaseOrder(_purchTable).createChangeRequest();

    please give me more shed on this

    thanks!

  • Suggested answer
    greengrimms Profile Picture
    1,400 on at
    RE: You cannot request a change, because the document is in state Draft. when auto submit the workflow in ax 2012 r3

    Hi,

    That's happening because of this piece of code:

    pastedimage1627048112447v1.png

    So when you set the ChangeRequestRequired field to No, you're skipping that validation:

    pastedimage1627048158871v2.png

    Also, from the functional side, the PO must be confirmed first in order to be sent to workflow (at least that's how it works in our business scenario)

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

Daivat Vartak – Community Spotlight

We are honored to recognize Daivat Vartak as our March 2025 Community…

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Kudos to the February 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... 293,245 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 231,923 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156 Moderator

Leaderboard

Product updates

Dynamics 365 release plans