How to approve and change status of work flow for purchase order

 Today we have a requirement that create a job and pass the purchase order number. They approve and confirm the po also change the workflow status.


So to done this requirement we have created one helper class and a job 

1) Create a helper class :- 


class AVAPurchaseOrderHelperClass

{

    //For workflow  enabled Po's, changing the status from draft to approved

    public static void updatePOStatusToApproved(PurchTable _purchTable)

    {

        PurchTable purchTableUPD;

              

        ttsbegin;

        select firstonly forupdate purchTableUPD

            where purchTableUPD.PurchId == _purchTable.PurchId;


        purchTableUPD.AVAPOWorkflowApprovedChk = NoYes::No;

        purchTableUPD.autoApproveChangeRequest(true);

        ttscommit;

    

    }


    //For workflow  enabled Po's, changing the status from approved to draft to update autoclose field in the PO line

    public static void updatePOStatusToDraft(PurchTable _purchTable)

    {

        ttsbegin;

        _purchTable.selectForUpdate(true);

        _purchTable.AVAPOWorkflowApprovedChk = NoYes::Yes;

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

        ttscommit;

    }


    public static Void updatePOAutoClose(PurchLine _purchLine)

    {

        ttsbegin;

        purchLine purchLineUPD = PurchLine::findRecId(_purchLine.RecId,true);

        purchLineUPD.AVAAutoClose = NoYes::Yes;

        purchLineUPD.doUpdate();

        ttscommit;

    }


    public static void confirmPO(PurchTable _purchTable)

    {

        ttsbegin;

        PurchFormLetter purchFormLetter;

        PurchFormLetter purchFormLetterPack;

        purchFormLetter = PurchFormLetter::construct(DocumentStatus::PurchaseOrder);

        purchFormLetter.update(_purchTable, _purchTable.PurchId,

                                    systemDateGet(),

                                    PurchUpdate::All,

                                    AccountOrder::None,

                                    NoYes::No,

                                    NoYes::no);

        ttscommit;

    }


}

=====================================================================


Step 2 :- Create a job to test 


class AVAApprovedPOJob

{

    /// <summary>

    /// Runs the class with the specified arguments.

    /// </summary>

    /// <param name = "_args">The specified arguments.</param>

    public static void main(Args _args)

    {

        PurchTable      purchTable = purchTable::find('WG-0072161');

        AVAPurchaseOrderHelperClass::updatePOStatusToApproved(purchTable);

        Info(strFmt("%1",purchTable.DocumentStatus));

    }


}



================================================================== 

Comments

Popular posts from this blog

Customization on Sales invoice Report in D365 F&O

75) COC - Create a coc of the table modified method

46) D365 FO: SHAREPOINT FILE UPLOAD USING X++