• Skip to main content
  • Skip to primary sidebar
  • Home
  • About
  • Recommended Readings
    • 2022 Book Reading
    • 2023 Recommended Readings
    • Book Reading 2024
    • Book Reading 2025
  • Supply Chain Management Guide
  • PKM
  • Microsoft Excel

Ali Raza Zaidi

A practitioner’s musings on Dynamics 365 Finance and Operations

Creating and consuming Custom Document Service in Dynamics Ax 2012 R3

September 15, 2014 by alirazazaidi

For one of Presentation on AIF, I build a custom Document Service based on custom table. To avoid any validation constraints I made a very simple custom table “StudentInfoTable”.

FieldName dataType
Roll Number string
FistName string
LastName string
Address string
DateOfBirth date.

 

Create a Unique Index on FirstName field, so Read and find method of custom Document service works fine.

 

 

In AOT under Query Node with Name AxdStudentInfo, create a new DataSource and add StudentInfoTable. Right click on field and set Dynamic Property to Yes

 

Query

 

Now right click on “StudentInfoTable” Node and set its Update properties to true, so Update methods will created against this query object

 

UpdateQuery

 

Now in Development environment from top menu click on AIF frame and then select on Create Document Service and click on it. For this result in running a Wizard

Menu

 

 

Select following options from Wizard, select the query which we create above mentioned drop down. Name the Document Name

 

9-14-2014 10-04-05 AM

Press Next button, from the next button check all the checkbox as per following screen shot.

9-14-2014 10-05-12 AM

Press on Next Button

9-14-2014 10-08-52 AM

Press on Generate button.

9-14-2014 10-12-39 AM

Press On Finished button.

There is possibility of errors in generated code, You can find complete code generated with wizard in private project in Dynamics Ax.

Private Project for Document Services

Right click on AxdStudentInfo and compile again.

You have delete two methods  cacheObject and cacheRecordRecord in AxStudentInfoTable and compile the whole project.

 

Now right click on StudentInfoService and set namespace

http://schemas.Student.com/ServiceContracts

Service reference

Now create a right on Service group Node and create a new service group.

 

Service Group

Drag and drop service node under Student InfoService group. So  Student Service will be available for in side service group.

 

Now generate Inc CIL or right click on StudentInfoServicegroup and click deploy

 

Deploy Service Group

 

 

 

 

 

 

After successful deployment you may find following info box

 

Service InfoBox

 

 

 

 

Now open a new work space and go at System Administration module and open in bound port under Application integration framework

In Bound Port


 

 

And Open Application Inbound framework

 

Address

Copy WSDL URL In my case it is

 

http://WIN-IKPOSIU2SGD:8101/DynamicsAx/Services/StudentInfoServiceGroup

 

now open Visual studio Project and create a new Console project I am more comfortable with C#.

Console

 

 

 

From Solution explore right click and add Service reference

ServiceReference2

 

 

Now we can use following code to create, Read, Update and delete methods

 

Create method

 

 

  StudentInfoRef.AxdEntity_StudentInfoTable _StudentInfo = new StudentInfoRef.AxdEntity_StudentInfoTable();

StudentInfoRef.AxdStudentInfo _Student = new StudentInfoRef.AxdStudentInfo();

_Student.StudentInfoTable = new StudentInfoRef.AxdEntity_StudentInfoTable[1] { _StudentInfo };

 

_StudentInfo.FirstName = "Ali";

_StudentInfo.LastName = " Raza";

_StudentInfo.Address = " Lahore";

_StudentInfo.DateOfBirth = new DateTime(1979, 4, 6);

StudentInfoRef.StudentInfoServiceClient _Client = new StudentInfoRef.StudentInfoServiceClient();

StudentInfoRef.CallContext _callContext = new StudentInfoRef.CallContext();

_callContext.Company = "USSI";

StudentInfoRef.EntityKey[] entityKeys = _Client.create(_callContext, _Student);

You can see create function works fine.
TableExploreCreate
In above mentioned code, Create method take two parameter, first is Call context, In Call context variable we can define legal entity where data will be inserted.

 

 

Read Method

 

Read method use EntityKey for searching criteria for example we want to search Student with First Name Ali following code will works for Us.

Read method works on keyField value. It is recommend that you will search records on the bases of Unique indexed based field.

 

 

 

StudentInfoRef.KeyField keyField = new StudentInfoRef.KeyField() { Field = "FirstName", Value = "Ali2" };

 

// Create an entity key instance and put in the key field data

StudentInfoRef.EntityKey entityKey = new   StudentInfoRef.EntityKey();

 

entityKey.KeyData   = new   StudentInfoRef.KeyField[1] { keyField };

// Create an array of entity keys and put in the previously

 

StudentInfoRef.EntityKey[] entityKeys = new StudentInfoRef.EntityKey[1] { entityKey };

 

 

StudentInfoRef.StudentInfoServiceClient _Client = new StudentInfoRef.StudentInfoServiceClient();

StudentInfoRef.CallContext _callContext = new StudentInfoRef.CallContext();

_callContext.Company = "USSI";

 

StudentInfoRef.AxdStudentInfo _StudentInfo = _Client.read(_callContext, entityKeys);

 

 

StudentInfoRef.AxdEntity_StudentInfoTable _StudentInfoTable = _StudentInfo.StudentInfoTable[0];

 

Console.WriteLine("First Name :" + _StudentInfoTable.FirstName);

Console.WriteLine("Last Name :" + _StudentInfoTable.LastName);

Console.WriteLine("Address :" + _StudentInfoTable.Address);

 

Console.ReadLine();

 

 

 

 

 

 

Update Method

Update in Document is two step process, first step to read the record based on field and second step to update the record which is return as result.

 

 

For example I want to update Address and Last Name of student. Following code works for me.

 

 

 

StudentInfoRef.KeyField keyField = new StudentInfoRef.KeyField() { Field = "FirstName", Value = "Ali2" };

 

// Create an entity key instance and put in the key field data

StudentInfoRef.EntityKey entityKey = new StudentInfoRef.EntityKey();

 

entityKey.KeyData = new StudentInfoRef.KeyField[1] { keyField };

// Create an array of entity keys and put in the previously

 

StudentInfoRef.EntityKey[] entityKeys = new StudentInfoRef.EntityKey[1] { entityKey };

 

 

StudentInfoRef.StudentInfoServiceClient _Client = new StudentInfoRef.StudentInfoServiceClient();

StudentInfoRef.CallContext _callContext = new StudentInfoRef.CallContext();

_callContext.Company = "USSI";

 

StudentInfoRef.AxdStudentInfo _StudentInfo = _Client.read(_callContext, entityKeys);

 

 

StudentInfoRef.AxdEntity_StudentInfoTable _StudentInfoTable = _StudentInfo.StudentInfoTable.First();

 

_StudentInfoTable.Address = "Lahore";

_StudentInfoTable.LastName = "Zaidi";

_StudentInfoTable.action = StudentInfoRef.AxdEnum_AxdEntityAction.update;

_StudentInfoTable.actionSpecified = true;

_Client.update(_callContext, entityKeys, _StudentInfo);

 

 

 

 

Delete Method

 

Delete Method works for same way, Send entity keys and call for Delete method.

 

StudentInfoRef.KeyField keyField = new StudentInfoRef.KeyField() { Field = "FirstName", Value = "Ali2" };

 

// Create an entity key instance and put in the key field data

StudentInfoRef.EntityKey entityKey = new StudentInfoRef.EntityKey();

 

entityKey.KeyData = new StudentInfoRef.KeyField[1] { keyField };

// Create an array of entity keys and put in the previously

 

StudentInfoRef.EntityKey[] entityKeys = new StudentInfoRef.EntityKey[1] { entityKey };

 

 

StudentInfoRef.StudentInfoServiceClient _Client = new StudentInfoRef.StudentInfoServiceClient();

StudentInfoRef.CallContext _callContext = new StudentInfoRef.CallContext();

_callContext.Company = "USSI";

_Client.delete(_callContext, entityKeys);


 

 

 

Filed Under: Dynamics AX 2012, Dynamics Ax 2012 Technical Side, Tips and tricks Tagged With: Aif Services, Dynamics Ax 2012, Dynamics Ax 2012 R3

Primary Sidebar

About

I am Dynamics AX/365 Finance and Operations consultant with years of implementation experience. I has helped several businesses implement and succeed with Dynamics AX/365 Finance and Operations. The goal of this website is to share insights, tips, and tricks to help end users and IT professionals.

Legal

Content published on this website are opinions, insights, tips, and tricks we have gained from years of Dynamics consulting and may not represent the opinions or views of any current or past employer. Any changes to an ERP system should be thoroughly tested before implementation.

Categories

  • Accounts Payable (2)
  • Advance Warehouse (2)
  • Asset Management (3)
  • Azure Functions (1)
  • Books (6)
  • Certification Guide (3)
  • Customization Tips for D365 for Finance and Operations (62)
  • D365OF (59)
  • Data Management (1)
  • database restore (1)
  • Dynamics 365 (58)
  • Dynamics 365 for finance and operations (135)
  • Dynamics 365 for Operations (165)
  • Dynamics AX (AX 7) (134)
  • Dynamics AX 2012 (274)
  • Dynamics Ax 2012 Forms (13)
  • Dynamics Ax 2012 functional side (16)
  • Dynamics Ax 2012 Reporting SSRS Reports. (31)
  • Dynamics Ax 2012 Technical Side (52)
  • Dynamics Ax 7 (65)
  • Exam MB-330: Microsoft Dynamics 365 Supply Chain Management (7)
  • Excel Addin (1)
  • Favorites (12)
  • Financial Modules (6)
  • Functional (8)
  • Implementations (1)
  • Lifecycle Services (1)
  • Logseq (4)
  • Management Reporter (1)
  • Microsoft Excel (4)
  • MS Dynamics Ax 7 (64)
  • MVP summit (1)
  • MVP summit 2016 (1)
  • New Dynamics Ax (19)
  • Non Defined (9)
  • Note taking Apps (2)
  • Obsidian (3)
  • Personal Knowledge Management (2)
  • PKM (13)
  • Power Platform (6)
  • Procurement (5)
  • procurement and sourcing (5)
  • Product Information Management (4)
  • Product Management (6)
  • Production Control D365 for Finance and Operations (10)
  • Sale Order Process (10)
  • Sale Order Processing (9)
  • Sales and Distribution (5)
  • Soft Skill (1)
  • Supply Chain Management D365 F&O (3)
  • Tips and tricks (278)
  • Uncategorized (165)
  • Upgrade (1)
  • Web Cast (7)
  • White papers (4)
  • X++ (7)

Copyright © 2025 · Magazine Pro On Genesis Framework · WordPress · Log in