Customer Address book relation for channel Database D365FO


Customer Address book relation for channel Database D365FO



Scenario:

Most of our D365FO Fellow are working with Retail where we sync customer with our channel database, and sometime we need to update the customer from POS as well, Sometime channel DB throw exception when while updating the customer information if AddressBook of the customer  customer is not properly set.

Its happens when we create customer using AX client or import them via DMF and didn't set the address book value.


So no need to worry using below code & query you can update the customers address book in bulk.

Image:




Code:

public void AddrssBookRelation()
    {
        DirAddressBookParty       dirAddressBookParty;
        DirAddressBook                   dirAddressBook;
        CustTable                              custTable;


        select RecId,Party from custTable
            where custTable.AccountNum==this.CustomerAccount;

        if(custTable)
        {
            select RecId from dirAddressBook
            where dirAddressBook.Name==this.CountryCode;

            if(dirAddressBook)
            {
                select RecId from dirAddressBookParty
                    where dirAddressBookParty.Party==custTable.Party && dirAddressBookParty.AddressBook==dirAddressBook.RecId;

                if(dirAddressBookParty.RecId==0)
                {
                    dirAddressBookParty.clear();
                    dirAddressBookParty.Party=custTable.Party;
                    dirAddressBookParty.AddressBook=dirAddressBook.RecId;
                    dirAddressBookParty.insert();
                }

            }
        }

    }



SQL Query:

INSERT INTO DirAddressBookParty (PARTY,ADDRESSBOOK,PARTITION)
select DISTINCT DirPartyLocation.PARTY,DirAddressBook.RECID,5637144576 from LogisticsPostalAddress
join DirPartyLocation on DirPartyLocation.LOCATION=LogisticsPostalAddress.LOCATION
Join LOGISTICSLOCATION on LOGISTICSLOCATION.RECID=LogisticsPostalAddress.LOCATION
join DirAddressBook on DirAddressBook.NAME=LogisticsPostalAddress.COUNTRYREGIONID
where DirPartyLocation.ISPRIMARY=1 and party in (select party from CUSTTABLE)
and LOGISTICSLOCATION.ISPOSTALADDRESS=1 and DirPartyLocation.ISPOSTALADDRESS=1 and DirPartyLocation.POSTALADDRESSROLES='Business'
and not exists (select 1 from DirAddressBookParty where DirAddressBookParty.PARTY=DirPartyLocation.PARTY and DirAddressBookParty.ADDRESSBOOK=DirAddressBook.RECID)
 and LogisticsPostalAddress.VALIDTO >=GETDate()

Customer Cancel Payment Transaction



Customer Cancel Payment Transaction 

Oftentimes Technical consultants receive the requirement to write some logic or feature where we can cancel the X number of payments by selecting many records at once.


class TMV_CustomerPaymentCancel
{

   

    public static void main(Args _args)
    {
        LedgerJournalTrans _ledgerJournalTrans;
        TMV_CustomerPaymentCancel objCancelPayment=new TMV_CustomerPaymentCancel();
        objCancelPayment.cancelpaymentExecution('R00007404',_ledgerJournalTrans);
    }

    public void cancelpaymentExecution(InvoiceId _invoiceid,LedgerJournalTrans _ledgerJournalTrans)
    {

        CustTrans custTransOffset;
       
        ReasonTable reasonTable;
        ReasonCode reasonCode;
        ReasonRefRecID reasonRefRecID;
     
        Args args;
 
        ;
        custTransOffset= this.findPaymentReference(_invoiceid);
        if(custTransOffset.RecId>0)
        {
            this.CancelPayment(custTransOffset, _ledgerJournalTrans);
        }

    }

    public CustTrans findPaymentReference(InvoiceId _invoiceid)
    {
        CustTrans custTrans,custTransOffset;

        custTrans = CustTrans::findFromInvoice(_invoiceid);
        select custTransOffset
            where custTransOffset.OffsetRecid==custTrans.RecId
            && custTransOffset.TransType==LedgerTransType::Payment;
        return custTransOffset;
    }

    public void CancelPayment(CustTrans custTransOffset,LedgerJournalTrans _ledgerJournalTrans)
    {
        CustVendPDCManager  custVendPDCManager;
        BankPaymCancel bankPaymCancel;
        Args    localArgs;
        if(custTransOffset.RecId)
        {
 
            infolog.clear();
            try
            {
                localArgs = new Args();

                bankPaymCancel = BankPaymCancel::newBankPaymCancel(custTransOffset);

                //  bankPaymCancel.parmReason(reasonTable.Reason);
                //   bankPaymCancel.parmReasonComment(reasonTable.Description);
                bankPaymCancel.parmTransDate(systemDateGet());
       
                localArgs.caller(bankPaymCancel);
                localArgs.record(custTransOffset);
                BankPaymCancel::serverRun(localArgs);
 
            }
            catch
            {
               


            }
           
        }
    }



    public  str getErrorStr()
    {
        SysInfologEnumerator enumerator;
        SysInfologMessageStruct msgStruct;
        Exception exception;
        str error;
        enumerator = SysInfologEnumerator::newData(infolog.cut());
        while (enumerator.moveNext())
        {
            msgStruct = new SysInfologMessageStruct(enumerator.currentMessage());
            exception = enumerator.currentException();
            error = strfmt("%1 %2", error, msgStruct.message());
        }
        return error;
    }

}

Reverse customer Posted Invoice


Reverse customer Posted Invoice 

Using below code you can reverse the posted invoice of the customer.


class DemoTransationReversal extends TransactionReversal_Cust
{
    public static DemoTransationReversal construct()
    {
        return new DemoTransationReversal();
    }

    public boolean showDialog()
    {
        return false;
    }

    public static void main(Args _args)
    {
        CustTrans custTrans;
        DemoTransationReversal demoTransationReversal;
        ReasonTable reasonTable;
        ReasonCode reasonCode;
        ReasonRefRecID reasonRefRecID;
        InvoiceId invoiceId;
        Args args;
        ;

        invoiceId = "0099";
        reasonCode = "DEMO Purpose";       
        reasonTable = ReasonTable::find(reasonCode);
        reasonRefRecID = ReasonTableRef::createReasonTableRef(
            reasonTable.Reason, reasonTable.Description);

        custTrans = CustTrans::findFromInvoice(invoiceId);
           
        if (custTrans.RecId && !custTrans.LastSettleVoucher)
        {
            args = new Args();
            args.record(custTrans);

            demoTransationReversal = DemoTransationReversal::construct();
            demoTransationReversal.parmReversalDate(systemDateGet());
            demoTransationReversal.parmReasonRefRecId(reasonRefRecID);
            demoTransationReversal.reversal(args);
           
            info(strFmt("%1 %2 %3 %4 reversed.",
                custTrans.Voucher,
                custTrans.TransDate,
                custTrans.Invoice,
                custTrans.Txt));
        }       
    }
}

SQL In Operator in D365FO


SQL In Operator in D365FO


Microsoft Introduce In Operator in X++ Syntax, but it will work with Enums only.

Following are the example how you can use this


SalesTable  salesTable;
container   con = [SalesType::Sales, SalesType::ReturnItem, SalesType::Subscription];
while select SalesId from salesTable
where salesTable.SalesType in con
{
Info(salesTable.SalesId);
}

Virtual Fields Vs Computed Fields

  Virtual Field: A virtual field in D365FO is a field that doesn't have a direct representation in the database. It's a field that y...