Skip to main content

Notifications

Community site session details

Community site session details

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

Change planned purchase order status as draft instead of default approved

(0) ShareShare
ReportReport
Posted on by 2,145

Hello Experts,

After searching code same as subjected topic I found it on internet but its is for 365F&O.

Could you please change it to AX 2012 R3. Codes are given below.

Thanks

code:-


/// 
/// extension of class: ReqTransPoMarkFirm
/// 
[ExtensionOf(classStr(ReqTransPoMarkFirm))]
final class ReqTransPoMarkFirmCFSClass_Extension
{
    public container conPurchOrders;

    /// 
    /// updatePurchTable
    /// 
    /// _purchTable
    protected void updatePurchTable(PurchTable _purchTable)
    {
        conPurchOrders  = _purchTable.PurchId;

        next updatePurchTable(_purchTable);
    }

    /// 
    /// purchTablePostProcessing
    /// 
    protected void purchTablePostProcessing()
    {
        next purchTablePostProcessing();

        for (int i = 1; i <= conLen(conPurchOrders); i  )
        {
            PurchTable purchTable = PurchTable::find(conPeek(conPurchOrders, i), true);

            if(purchTable.RecId)
            {
                ttsbegin;
                //delete the version created for po
                PurchTableVersion purchTableVersion = PurchTableVersion::findLatest(purchTable.PurchId, purchTable.DataAreaId, true);

                if(purchTableVersion.RecId)
                {
                    purchTableVersion.delete();
                }

                purchTable.ChangeRequestRequired = NoYes::No;
                purchTable.DocumentState         = VersioningDocumentState::Draft;
                purchTable.update();

                ttscommit;
            }
        }
    }

}

  • Gunjan Bhattachayya Profile Picture
    35,421 on at
    RE: Change planned purchase order status as draft instead of default approved

    Hi Faiz,

    If the issue is resolved, please mark the helpful answer(s) as Verified.

  • Suggested answer
    Gunjan Bhattachayya Profile Picture
    35,421 on at
    RE: Change planned purchase order status as draft instead of default approved

    Hi Faiz,

    In that case, you can uncomment the changes you did and comment out the method call from the method "firmSelectedPlannedOrders" (in case you don't need this functionality at all) or put some condition to execute the method. I am highlighting the method call in the screenshot.

    This should resolve your issue.

    pastedimage1603967646456v1.png

  • faiz7049 Profile Picture
    2,145 on at
    RE: Change planned purchase order status as draft instead of default approved

    Hi Gunjan,

    I just commented some piece of code under method autoApproveFirmedPlannedPurchaseOrders.

    It works for me...

    private void autoApproveFirmedPlannedPurchaseOrders()
    {
        SetEnumerator enumerator;
        PurchTable    purchOrder;
    
        ttsbegin;
        enumerator = purchIdsToAutoApprove.getEnumerator();
        while (enumerator.moveNext())
        {
            purchOrder = PurchTable::find(enumerator.current(), true);
    
    
           /*
           //Business logic commented because need PO approve throuhg workflow date 29-Oct-2020
    
           if (purchOrder.ChangeRequestRequired && purchOrder.DocumentState == VersioningDocumentState::Draft)
            {
                purchOrder.autoApproveChangeRequest();
            }
    
    
           */
        }
    
    
    
        purchIdsToAutoApprove = new Set(Types::String);
    
        ttscommit;
    }

  • Suggested answer
    Gunjan Bhattachayya Profile Picture
    35,421 on at
    RE: Change planned purchase order status as draft instead of default approved

    Hi Faiz,

    You need to check where the purchase order status changes. There is a method in Classes\ReqTransPOMarkFirm called "submitPurchOrdersToWorkflow". I think this is where the state is changing for the POs. You can try commenting this method and check if that works.

  • faiz7049 Profile Picture
    2,145 on at
    RE: Change planned purchase order status as draft instead of default approved

    Thanks Will,

    So I have to create new class called "subReqTransPoMarkFirm" and inside method " protected void purchTablePostProcessing()".

    How class "subReqTransPoMarkFirm" will call.

  • WillWU Profile Picture
    22,352 on at
    RE: Change planned purchase order status as draft instead of default approved

    Hi  faiz7049,

    See:

    class subReqTransPoMarkFirm extends ReqTransPoMarkFirm
        {
            public container conPurchOrders;
            
            protected void updatePurchTable(PurchTable _purchTable)
            {
                conPurchOrders  = _purchTable.PurchId;
    
                super();
            }
            protected void purchTablePostProcessing()
            {
                super();
                for (int i = 1; i <= conLen(conPurchOrders); i  )
                {
                    PurchTable purchTable = PurchTable::find(conPeek(conPurchOrders, i), true);
    
                    if(purchTable.RecId)
                    {
                        ttsbegin;
                        //delete the version created for po
                        PurchTableVersion purchTableVersion = PurchTableVersion::findLatest(purchTable.PurchId, purchTable.DataAreaId, true);
    
                        if(purchTableVersion.RecId)
                        {
                            purchTableVersion.delete();
                        }
    
                        purchTable.ChangeRequestRequired = NoYes::No;
                        purchTable.DocumentState         = VersioningDocumentState::Draft;
                        purchTable.update();
    
                        ttscommit;
                    }
                }
            }
            
        }

  • faiz7049 Profile Picture
    2,145 on at
    RE: Change planned purchase order status as draft instead of default approved

    Yes @Gunjan

  • Gunjan Bhattachayya Profile Picture
    35,421 on at
    RE: Change planned purchase order status as draft instead of default approved

    Hi faiz,

    What exactly is the requirement here? Are you trying to update the status of the purchase orders created from planned purchase orders?

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!

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,323 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 232,191 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,158 Moderator

Leaderboard

Product updates

Dynamics 365 release plans