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()

5 comments:

  1. Thank you for sharing such a nice and interesting blog with us.

    ReplyDelete
  2. Its very easy for understanding. Very good explanation. Thank you for sharing.
    MS Dynamics Technical Online Training

    ReplyDelete
  3. My name is Mrs Nadia Albert from Russia, And i am a happy woman today through the help of a Loan lender, Mr Russ Harry. I will refer any person that is looking for a loan to this Loan firm. He gave  happiness to me and my family, i was in need of a loan of $500,000.00 to start my life all over as i am a single mother. I met this honest and GOD fearing man loan lender that help me with a loan of $500,000.00 US Dollar, at a low Rate. He is a God fearing man, if you are in need of loan and you will pay back the loan please contact him Via E-mail-Elegantloanfirm@hotmail.com /Whatsapp number+393511617486

    ReplyDelete
  4. My name is Mr. Klaus Dieter, I work for the French financial institution Crédit Mutuel with the partnership of the bank BNP Paribas, we offer you offers at an interest rate of 3% per year, to start with new projects:
    - You have unpaid debt.
    - Buying a new house.
    - buy a new car.
    - Buying a new apartment or property.
    Get personal loans, business loans.
    If you would like loans for setting up your business and project, do not hesitate to send us an email:
    bnpfinanzenhilfe@gmail.com

    Whatsapp: +4917694954827

    ReplyDelete
  5. Emergency Cash Loans Hello Everybody, My name is Mrs. Phyllis Sue South. I live in UK London and i am a happy woman today? and i told my self that any lender that rescue my family from our poor situation, i will refer any person that is looking for loan to him, he gave me happiness to me and my family, i was in need of a loan of $350,000.00 to start my life all over as i am a single mother with 2 kids I met this honest and GOD fearing man loan lender that help me with a loan of $350,000.00 U.S. Dollar, he is a GOD fearing man, if you are in need of loan and you will pay back the loan please contact him tell him that is Mrs. Phyllis Sue South that refer you to him. contact Dr. James Eric via email: financialserviceoffer876@gmail.com Whats-App +918929509036

    ReplyDelete

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...