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 :
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,382

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;
            }
        }
    }

}

I have the same question (0)
  • Gunjan Bhattachayya Profile Picture
    35,423 on at

    Hi faiz,

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

  • faiz7049 Profile Picture
    2,382 on at

    Yes @Gunjan

  • WillWU Profile Picture
    22,361 on at

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

    Thanks Will,

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

    How class "subReqTransPoMarkFirm" will call.

  • Suggested answer
    Gunjan Bhattachayya Profile Picture
    35,423 on at

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

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

    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

  • Gunjan Bhattachayya Profile Picture
    35,423 on at

    Hi Faiz,

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

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 > Finance | Project Operations, Human Resources, AX, GP, SL

#1
Martin Dráb Profile Picture

Martin Dráb 451 Most Valuable Professional

#2
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 428 Super User 2025 Season 2

#3
BillurSamdancioglu Profile Picture

BillurSamdancioglu 239 Most Valuable Professional

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans