How to write Download Job or Push Job in D365 for new Custom Table?

 If you want to write the download/push job in D365. Please follow the following steps;

Step # 1:

You have to create the new Custom Table in the dbo schema of the database by using AOT. 

Or you can create it simply in the database for testing.

For Example. 

You create a Table of books.

dbo.DRBOOK

Code:

IF  NOT EXISTS (SELECT * FROM sys.objects

WHERE object_id = OBJECT_ID('[dbo].[DRBOOK]') AND type in (N'U'))

BEGIN

CREATE TABLE [dbo].[DRBOOK](

TITLETAG nvarchar(MAX) NOT NULL,

[DATAAREAID] nvarchar(4) NOT NULL,

[PARTITION] bigint NOT NULL,

[RECID] bigint NOT NULL

    CONSTRAINT [I_dbo_DRBOOK] PRIMARY KEY CLUSTERED (

[TITLETAG] ASC,

[DATAAREAID] ASC,

[PARTITION] ASC

)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]

) ON [PRIMARY]

END;


GO


GRANT SELECT, INSERT, UPDATE, DELETE ON OBJECT::[dbo].[DRBOOK] TO [DataSyncUsersRole]

GO

GRANT SELECT ON [dbo].[DRBOOK] TO [UsersRole];

GO

GRANT SELECT ON [dbo].[DRBOOK] TO [DeploydboensibilityRole]

GO

Step # 2 :

Now create the same table in the EXT schema as shown below;


----------------------------TABLE [ext].[DRBOOK] <START>---------------------------------------------


IF  NOT EXISTS (SELECT * FROM sys.objects

WHERE object_id = OBJECT_ID('[ext].[DRBOOK]') AND type in (N'U'))

BEGIN

CREATE TABLE [ext].[DRBOOK](

TITLETAG nvarchar(MAX) NOT NULL,

[DATAAREAID] nvarchar(4) NOT NULL,

[PARTITION] bigint NOT NULL,

[RECID] bigint NOT NULL

    CONSTRAINT [I_ext_DRBOOK] PRIMARY KEY CLUSTERED (

[TITLETAG] ASC,

[DATAAREAID] ASC,

[PARTITION] ASC

)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]

) ON [PRIMARY]

END;


GO


GRANT SELECT, INSERT, UPDATE, DELETE ON OBJECT::[ext].[DRBOOK] TO [DataSyncUsersRole]

GO

GRANT SELECT ON [ext].[DRBOOK] TO [UsersRole];

GO

GRANT SELECT ON [ext].[DRBOOK] TO [DeployextensibilityRole]

GO


----------------------------TABLE [ext].[DRBOOK] <END>---------------------------------------------

Step # 3 :

Now create a project with the name DRRetailCDXSeedData in the visual studio.

Step # 4 : 

Create an XML file in which you write the job as shown and save the file with the name DRRetailCDXSeedDataAX7Resource

<RetailCdxSeedData ChannelDBMajorVersion="7" ChannelDBSchema="ext" Name="AX7">
  <Subjobs>
    <Subjob Id="DRBOOK" TargetTableSchema="ext" AxTableName= "DRBOOK">
      <ScheduledByJobs>
        <ScheduledByJob>7000</ScheduledByJob>
      </ScheduledByJobs>
      <AxFields>
        <Field Name="TITLETAG"/>
        <Field Name="PARTITION"/>
        <Field Name="RECID"/>
      </AxFields>
    </Subjob>
  </Subjobs>
</RetailCdxSeedData>

Step # 5 :

Now Right-click the project, and then select Add > New Item.

Step # 6 :

In the Add New Item dialog box, select Resources, name the resource file DRRetailCDXSeedDataAX7Resource and then select Add.

Step # 7: 

In the Select, a Resource file dialog box, find the resource file that you created in Step 4 and then select Open.

Step # 8:

Add a new handler class with the name DRRetailCDXSeedDataAX7EventHandler and write the code in the class as shown below.

/// <summary>
/// The event handler class for <c>RetailCDXSeedDataBase</c>
/// </summary>
class DRRetailCDXSeedDataAX7EventHandler
{
  
    /// <summary>
    /// delegate class for registerCDXSeedDataExtension
    /// </summary>
    /// <param name="_originalCDXSeedDataResource">_originalCDXSeedDataResource</param>
    /// <param name="_resources">_resources</param>
    [SubscribesTo(classStr(RetailCDXSeedDataBase), delegateStr(RetailCDXSeedDataBase, registerCDXSeedDataExtension))]
    public static void RetailCDXSeedDataBase_registerCDXSeedDataExtension(str _originalCDXSeedDataResource, List _resources)
    {
        if (_originalCDXSeedDataResource == resourceStr(RetailCDXSeedDataAX7))
        {
            _resources.addEnd(resourceStr(DRRetailCDXSeedDataResource));
        }
    }

}

Step # 9:

Now build the project and Sync database by right click on the project.

Step # 10: 

Go to the AX/AOS site of D365 and search for Initialize commerce scheduler. Open the form delete the existing configuration to Yes and run.

Step # 11:

Go to the distribution schedule by searching on the AX/AOS site of D365 and see your JOB is there with 7000.

Step # 12:

Now insert one row in the dbo.DRBOOK table from the database and run the job 7000.

Step # 13:

Go to Download Session of the AX/AOS Site and check the 7000 jobs are Applied. If applied then go to the database and check the table ext.DRBBOOK. 

Your Data is Sync. Thanks.

Note:
If you any Questions and concern. Please add in the Comment Section.



Comments

Popular posts from this blog

Create custom workflow in D365 X++

Convert amount from one currency to another currency using X++

How to Create Extended Data Types (EDTs) in Finance and Operations of Dynamics 365 -- F&O Customization Part 2