Monday, May 12, 2025

purchase order confirmation, product receipt, Invoice classes and methods

 Purchase order confirmation, product receipt, Invoice, cancel  classes and methods

Let's assume that we have the requirement to send business events after purchase order confirmation, cancel, product receipt and invoice Fully (header level)


1) purchase order cancel 

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

[ExtensionOf(classstr(PurchCancel))]

public final class TestPurchCancel_Extension

{

public void run()

{   

PurchTable  purchTableOrig, purhtableLoc;

next run();

purchTableOrig = this.parmPurchTable();

                select firstonly purhtableLoc

where purhtableLoc.PurchId         == purchTableOrig.PurchId

&& purhtableLoc.PurchStatus == PurchStatus::Canceled;


    if(purhtableLoc.RecId)

{

//Write your logic

}

}

}



2) product receipt and invoice 
=====================

[ExtensionOf(classstr(PurchFormletter))]

public final class TestPurchFormLetter_Extension

{

    public void run()

    {

        PurchTable          purchTableOrig, purhtableLoc;

        next run();


        purchTableOrig = purchFormLetterContract.parmPurchTable();


        select firstonly purhtableLoc

            where purhtableLoc.PurchId      == purchTableOrig.PurchId

               &&(purhtableLoc.PurchStatus  == PurchStatus::Received||

                  purhtableLoc.PurchStatus  == PurchStatus::Invoiced);

        

        if(purhtableLoc.RecId)

        {

            //Write your logic 

        }

        

    }

}


3) purchase order confirmation

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

[ExtensionOf(classstr(SourceDocumentStateInProcess))]

public final class TestSourceDocumentStateInProcess_Extension

{

    protected boolean doTransition()

    {

        next doTransition();

        

        if (targetSourceDocumentAccountingStatus == SourceDocumentAccountingStatus::Completed)

        {

            PurchTable purchTable =                                PurchTable::findSourceDocumentHeader(sourceDocumentHeader.RecId);

            VendPurchOrderJour vendPurchOrderJour = VendPurchOrderJour::findByPurchId(purchTable.PurchId);

            if(vendPurchOrderJour.RecId)

            {

              //Write your logic

            }

        }

        return true.

    }

}


while doing purchase order confirmation, product receipt and invoice system will create journals and post and update the status in PurchTable  .after updating status or creating journal if we want any customizations we can do in below method  


[ExtensionOf(classstr(FormletterService))]
public  final class TestFormLetterService_Extension
{
    protected void processJournal(Printout _printout)
    {
       
        VendPurchOrderJour  vendPurchOrderJourloc;
        PurchTable          purchTableLoc;
vendinvoicejour     vendinvoicejour     
VendPackingSlipJour VendPackingSlipJour;

        next processJournal(_printout);

        purchTableLoc= formLetterContract.parmsourceTable() as PurchTable;

//purchase order confirmation
            select  firstonly vendPurchOrderJourloc
            where vendPurchOrderJourloc.PurchId         == purchTableLoc.PurchId
                && vendPurchOrderJourloc.DataAreaId == purchTableLoc.DataAreaId;
            if(vendPurchOrderJourloc.recid)
            {
            //write your logic 
    }
//for packingslip post
select  firstonly VendPackingSlipJour
            where VendPackingSlipJour.PurchId         == purchTableLoc.PurchId
                && VendPackingSlipJour.DataAreaId == purchTableLoc.DataAreaId;
            if(VendPackingSlipJour.recid)
            {
            //write your logic 
    }

//for invoice post
select  firstonly vendinvoicejour     
            where vendinvoicejour.PurchId         == purchTableLoc.PurchId
                && vendinvoicejour.DataAreaId == purchTableLoc.DataAreaId;
            if(vendinvoicejour.recid)
            {
            //write your logic 
    }
        
    }

}

Delete TFS Workspace Through command prompt D365 FO

Requirement: where I have situation need to configure the TFS in my Development machine but getting error when we map metadata.  cause of t...