Showing posts with label Retail. Show all posts
Showing posts with label Retail. Show all posts

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

CDX Extensibility D365 MPOS


CDX Extensibility D365 MPOS



In one of our projects, we have a requirement to Add few fields to the customer group table and sync these fields with the MPOS channel database.

To fulfill this requirement we were following this link




Lets Begin


Step-1 
Create New straight table SLD_CustGroup and the same table we created in the Channel database as well.


Step-2 
Take Insert and update post handler of Cust group and perform insert and update on new table like below screenshot.










Step-3 
Create a new resource file to add all custom job information. Here is the template for the resource file and save it on any path.

<RetailCdxSeedData ChannelDBMajorVersion="7" ChannelDBSchema="ext" Name="AX7">
  <Subjobs>
    <Subjob Id="SLD_CustGroup" TargetTableSchema="ext" AxTableName="SLD_CustGroup" IsUpload="false">
      <ScheduledByJobs>
        <ScheduledByJob>1010</ScheduledByJob>
        <!--add existing sub-job to another job-->
      </ScheduledByJobs>
      <AxFields>
        <Field Name="CustGroup"/>
        <Field Name="SLD_PurchaseLimit"/>
        <Field Name="SLD_AllowSale"/>
        <Field Name="RecId"/>
      </AxFields>
    </Subjob>
  </Subjobs>
</RetailCdxSeedData>



Following is some information about tags of XML. You can find the detail on this Link

  • ChannelDBSchema – The extension schema that you created in the channel database.
  • TargetTableSchema – The extension schema that you created in the channel database to add your custom tables.
  • AxTableName – The table name.
  • IsUpload – A flag that determines whether the job is a rush job or a pull job. (In other words, the flag indicates whether you want to send data from Retail HQ to the channel database or pull data from the channel database to Retail HQ). The default value is false, which indicates that you're sending data from Retail HQ to the channel database.
  • ScheduledByJob – This resource file contains one or more sub-jobs.
  • Subjob – Each table is added as a sub-job, and each sub-job is scheduled by one or more scheduler jobs.
  • TargetTable – The name of the channel database table. This table is the target table that the push job or pull job must send data to. If a value isn't specified, the system assumes that name of the target table and the name of the source table are the same.

Step-4 Add a new resource file and associate the XML file with 







Step-5
Subscribe to the Delegate registerCDXSeedDataExtension of RetailCDXSeedDataBase in the new class and write the following code to load your newly created Resource file.


Add the resource like below 
For Example
   resources.addEnd(resourceStr(RetailCDXSeedData_CustGroup));

Step-6 
Now perform the build complete model and Sync database.

Step-7
To initialize or reinitialize the CDX module with the customized configuration, follow these steps:
  1. Go to Retail > Headquarters setup > Retail scheduler > Scheduler jobs > Initialize retail scheduler.
  2. In the dialog box that appears, select Delete existing configuration.
  3. Select OK to start the initialization.
    When the initialization is completed, the CDX scheduler jobs, sub-job definitions, and distribution schedules are updated by using the original RetailCDXSeedDataAX7 resource and the customized RetailCDXSeedData_CustGroup resource.

Step-8
For Verification search Scheduler jobs in AX and search bar job 1010.  You will find the sub job please check the below screenshot.



Step-9
Click on Sub job to verify that fields are appearing or not.


Feel free to contact me if you are facing any issues.


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