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()
Thank you for sharing such a nice and interesting blog with us.
ReplyDeleteIts very easy for understanding. Very good explanation. Thank you for sharing.
ReplyDeleteMS Dynamics Technical Online Training
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
ReplyDeleteMy 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:
ReplyDelete- 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
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