Showing posts with label Update Custom Fields. Show all posts
Showing posts with label Update Custom Fields. Show all posts

Wednesday, February 22, 2023

update custom fields in vendInvoiceInfoTable from PurchTable while invoicing the purchase order in D365FO

 update custom fields in vendInvoiceInfoTable from PurchTable while invoicing the purchase order in D365FO. While invoicing the purchase order system will create a pending vendor invoice.

I have added a few custom fields in the purchase order header and purchase order line. So, I need to transfer the data from PurchTable to vendInvoiceInfoTable. 

Check the below code.


For line fields:

[ExtensionOf(classStr(PurchFormletterParmData))]
internal final class PurchFormLetterParmData_Extension
{
    protected void createParmLineRecord(VendDocumentLineMap purchParmLine, PurchLine purchLine, 
					VendDocumentLineAssetMap purchParmLine_Asset, TradeLineRefId tableRef, 
					container quantities, container cwQuantities)
    {
        if (_purchParmLine.TableId == tableNum(VendInvoiceInfoLine))
        {
            VendInvoiceInfoLine vendInvoiceInfoLine = _purchParmLine;

            vendInvoiceInfoLine.Field1  = _purchLine.Field1;
            vendInvoiceInfoLine.Field2  = _purchLine.Field2;
        }
        
        next createParmLineRecord(_purchParmLine, purchLine, purchParmLine_Asset, 
						tableRef, quantities, _cwQuantities);
    }

}


For Header and line fields:

[ExtensionOf(classStr(PurchFormletterParmDataInvoice))] 
final class VendInvoiceInfoLine_Extension 
{ 
   // Header fields update
   protected void createInvoiceHeaderFromTempTable() 
   { 
      vendInvoiceInfoTable vendInvoiceInfoTable; 
      PurchTable           purchtable; 

       next createInvoiceHeaderFromTempTable(); 

       select forupdate vendInvoiceInfoTable 
           where vendInvoiceInfoTable.ParmId == this.parmId(); 
           //&& vendInvoiceInfoTable.PurchId == purchtable.PurchId; 
            
       purchtable = PurchTable::find(vendInvoiceInfoTable.PurchId); 

       // Code
       ttsbegin; 
       vendInvoiceInfoTable.Field2 	= purchtable.Field2; 
       vendInvoiceInfoTable.Field2 	= purchtable.Field2; 
       vendInvoiceInfoTable.update(); 
       ttscommit; 

    } 
  
   // Line fields update
   protected void createParmLinesAndTable() 
   { 
       VendInvoiceInfoLine vendInvoiceInfoLine; 
       PurchLine           purchline; 
	   
       next createParmLinesAndTable(); 

       while select forupdate vendInvoiceInfoLine 
           where vendInvoiceInfoLine.ParmId == this.parmId() 
       { 
            purchline = PurchLine::findRecId(vendInvoiceInfoLine.PurchLineRecId); 
		
            // Code
            ttsbegin; 
	    vendInvoiceInfoLine.Field1 = purchline.Field1; 
            vendInvoiceInfoLine.Field2 = purchline.Field2; 
	    vendInvoiceInfoLine.update(); 
	    ttscommit; 
       } 

   } 
} 


Keep Daxing!!

Tuesday, January 24, 2023

update custom fields in PurchTable from SalesTable while creating purchase order from sales order in D365FO

 I got a requirement to update custom fields in PurchTable from SalesTable while creating purchase order from sales order in D365FO.


For this I have extended the "PurchAutoCreate_Sales" class.


[ExtensionOf(classStr(PurchAutoCreate_Sales))]
public final class PurchAutoCreate_Sales_Extension //extends     PurchAutoCreate
{
        // Populating header details
	void setPurchTable()
	{
	    next setPurchTable();

	    /*if (!salesLine)
	    {
			salesLine = SalesLine::findRecId(tmpPurchLinePrice.SalesLineRefRecId, true);
	    }*/

	    purchTable.NewField1 = salesTable.NewField1;
	}

	// Populating Line details
	protected PurchLine initPurchLine()
	{
	    PurchLine localPurchLine = next initPurchLine();

	    localPurchLine.NewField1 = salesLine.NewField1;
	}
}


Keep Daxing!!

Monday, May 23, 2022

update custom fields in BankAccountTrans from LedgerJournalTrans during the posting of journal in D365FO

 update custom fields in BankAccountTrans from LedgerJournalTrans during the posting of the journal in D365FO. Here I am writing the code in the insert method for this I have used a pre-event handler. Check the below code.


class BankAccountTrans_Events
{
    [PreHandlerFor(tableStr(BankAccountTrans), tableMethodStr(BankAccountTrans, insert))]
    public static void BankAccountTrans_Pre_insert(XppPrePostArgs args)
    {
        BankAccountTrans    bankAccountTrans = Args.getThis();
        LedgerJournalTrans  ledgerJournalTrans;

        if (bankAccountTrans.SourceRecId && bankAccountTrans.SourceTableId 
                && bankAccountTrans.SourceTableId == tableNum(LedgerJournalTrans))
        {
            select firstonly1 ledgerJournalTrans
                where ledgerJournalTrans.RecId == bankAccountTrans.SourceRecId;

            bankAccountTrans.NewField1 = ledgerJournalTrans.NewField1;
            bankAccountTrans.NewField2 = ledgerJournalTrans.NewField2;
        }
    }
}


Keep daxing!!


Ref : https://allaboutdynamic.com/2018/06/23/d365-ax7-update-custom-fields-in-bankaccounttrans-from-ledgerjournaltrans/

Update Custom Fields In CustTrans/VendTrans From LedgerJournalTrans during the posting of journal in D365FO.

 For Update Custom Fields In CustTrans/VendTrans From LedgerJournalTrans during the posting of the journal in D365FO. We have 2 ways.


Way 1:

For Vend trans:

[ExtensionOf(classStr(VendVoucherJournal))]
final class VendVoucherJournal_Extension
{
    protected void initCustVendTrans(CustVendTrans custVendTrans, 
                                        LedgerVoucher _ledgerPostingJournal, 
                                        boolean _useSubLedger = false)
    {
        LedgerJournalTrans    ledgerJournalTrans;
        VendTrans             vendTrans;

        next initCustVendTrans(custVendTrans, _ledgerPostingJournal, _useSubLedger);

        if (common.TableId == tablenum(LedgerJournalTrans))
        {
            ledgerJournalTrans = common;
            vendTrans = custVendTrans;


            // Add new fields here.
            vendTrans.NewField1 = ledgerJournalTrans.NewField1;

            custVendTrans = vendTrans;

        }
    }

}


For cust trans:

[ExtensionOf(classStr(CustVoucherJournal))]
final class CustVoucherJournal_Extension
{
    protected void initCustVendTrans(
                                CustVendTrans custVendTrans,
                                LedgerVoucher _ledgerPostingJournal,
                                boolean _useSubLedger = false)
    {
        LedgerJournalTrans ledgerJournalTrans;
        recId              recId;
        CustTrans          custTrans;


        next initCustVendTrans(custVendTrans, _ledgerPostingJournal, _useSubLedger);

        if (common.TableId == tableNum(LedgerJournalTrans))
        {
            recId               = common.RecId;
            ledgerJournalTrans  = LedgerJournalTrans::findRecId(recId, false);
            //ledgerJournalTrans = common;

            custTrans = custVendTrans;

            // Add new fields here.
            custTrans.NewField1 = ledgerJournalTrans.NewField1;

            custVendTrans = custTrans;// need to reassign the buffer
        }
    }
}



Way 2:

[ExtensionOf(classStr(CustVendVoucher))]
final class CustVendVoucher_Extension
{

    public void post(
        LedgerVoucher _ledgerPostingJournal,
        CustVendTrans _custVendTrans,
        NoYes _approval,
        UnknownNoYes _euroTriangulation,
        boolean _withHoldTaxType,
        boolean _useSubLedger)
    {

        LedgerJournalTrans  ledgerJournalTransLocal;
        VendTrans           vendTrans;
        CustTrans           custTrans;

        next post(_ledgerPostingJournal, _custVendTrans, 
                    _approval, _euroTriangulation, 
                    _withHoldTaxType, _useSubLedger);

        if (common.TableId == tableNum(LedgerJournalTrans))
        {
            ledgerJournalTransLocal = common;

            if (_custVendTrans.tableid == tableNum(vendTrans))
            {
                ttsbegin;

                select forupdate vendTrans
                    where vendTrans.RecId == _custVendTrans.RecId;

                if (vendTrans.RecId)
                {
                    vendTrans.NewField1 = ledgerJournalTransLocal.NewField1;
                    vendTrans.Update();
                }
                ttscommit;
            }
            else if (_custVendTrans.tableid == tableNum(CustTrans))
            {
                ttsbegin;

                select forupdate custTrans
                    where custTrans.RecId == _custVendTrans.RecId;

                if (custTrans.RecId)
                {
                    custTrans.NewField1 = ledgerJournalTransLocal.NewField1;
                    custTrans.Update();
                }
                ttscommit;
            }
        }
    }
}


Ref : update-custom-fields-in-custtrans-vendtrans-from-ledgerjournaltrans-during-the-posting-of-journal


Keep Daxing!!