• 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

Aif Services

Exploring The SalesSalesOrderservice AIF Document Service In Dynamics Ax 2012 R3

October 10, 2014 by alirazazaidi

 

For my session for Integration with Dynamics Ax 2012. I have to consume SalesSalesOrderSerivce. In this article I am configure and consume Sales Order service and share c# code for calling a Sales service and consume.

 

Enable the methods and configure the inbound port. For this you have to go at following link and open AIf Inbound

Aif Link

 

Right click on AIF menu and create a New

set the Name there “ for example I create the port with Name “MySalesOrderService”.

10-10-2014 7-58-10 PM

Click on Service Operations add following one

Selection

Click on arrow button and add these method to service

Selected

Now click on Close button to close it.

Now click to check box to enable data policy button document. Click on it.

enable the Data policy

 

New screen open for all possible fields, Click on Element to sort the list, Enable following fields which are minimum required for Sales Order creation.

Mendatory Selection

 

 

 

Now save it. From port screen enable logging and Click on activate, Wait it will take time to deploy the service on port.

Activate

Info log appear to tell that port is successfully active.

InfoLog

 

Now copy the WSDL url

Wsdl

 

 

Create a new Console application in Visual studio, I am more familiar with C# so I created a console application in C#.

Add new Service reference and set its name “SalesOrderService” and get methods from WSDL.

SalesOrder Service Reference

 

Now Click on Ok button.

 

 

Calling the Create Method.

 


var line = new SalesOrderService.AxdEntity_SalesLine()

{

ItemId = “D0001”,

SalesQty = 42,

SalesUnit = “ea”

SalesOrderService.AxdEntity_InventDim inventDim = new SalesOrderService.AxdEntity_InventDim();
inventDim.InventSiteId = “JS”;

InventDim = new SalesOrderService.AxdEntity_InventDim[] {inventDim};

 

};

 

var order = new SalesOrderService.AxdEntity_SalesTable()

{

CustAccount = “US-003”,

PurchOrderFormNum = “ffg”,

ReceiptDateRequested = DateTime.Now.Date,

 

SalesLine = new SalesOrderService.AxdEntity_SalesLine[] { line }

};

 

//   SalesOrderService. _salesOrder= new SalesOrderService.AxdSalesOrder();

 

 

var orderList = new SalesOrderService.AxdEntity_SalesTable[] { order };

var callContext = new SalesOrderService.CallContext() { Company = “USMF” };

SalesOrderService.SalesOrderServiceClient client = new SalesOrderService.SalesOrderServiceClient();

 

 

//   _salesOrder.SalesTable=orderList;

try

{

client.create(callContext, orderList);

 

 

//  client.create(callContext, orderList);

client.Close();

}

catch

{

client.Abort();

throw;

}

 

Read Method Code

try

{

SalesOrderService.KeyField keyField = new SalesOrderService.KeyField() { Field = “SalesId”, Value = “000767” };

 

 

 

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

 

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

 

 

 

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

 

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

 

 

 

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

 

 

 

 

 

SalesOrderService.SalesOrderServiceClient _Client = new SalesOrderService.SalesOrderServiceClient();

 

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

 

_callContext.Company = “USMF”;

 

 

SalesOrderService.AxdEntity_SalesTable[] _SalesOrder= _Client.read(_callContext, entityKeys);

 

 

SalesOrderService.AxdEntity_SalesTable _SalesTable = _SalesOrder[0];

SalesOrderService.AxdEntity_SalesLine _SalesLineTable = _SalesTable.SalesLine[0];

Console.WriteLine(“Account Num : ” + _SalesTable.CustAccount.ToString());

Console.WriteLine(“Order date  : ” + _SalesTable.ReceiptDateRequested.ToString());

Console.WriteLine(“ItemId  : ” + _SalesLineTable.ItemId.ToString());

Console.WriteLine(“QTy  : ” + _SalesLineTable.SalesQty.ToString());

Console.WriteLine(“Sales Unit  : ” + _SalesLineTable.SalesUnit.ToString());

_Client.Close();

Console.ReadKey();

}

catch

{

//     client.Abort();

throw;

}

 

 

Update Method Call code

 


SalesOrderService.KeyField keyField = new SalesOrderService.KeyField() { Field = "SalesId", Value = "000756" };

 

 

 

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

 

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

 

 

 

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

 

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

 

 

 

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

 

 

 

 

 

SalesOrderService.SalesOrderServiceClient _Client = new SalesOrderService.SalesOrderServiceClient();

 

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

 

_callContext.Company = “USMF”;

 

 

 

SalesOrderService.AxdEntity_SalesTable[] _SalesOrderList = _Client.read(_callContext, entityKeys);

 

 

SalesOrderService.AxdEntity_SalesTable _SalesOrderTable = _SalesOrderList.First();

SalesOrderService.AxdEntity_SalesLine SalesLine = _SalesOrderTable.SalesLine.First();

decimal salesQty = 50;

SalesLine.SalesQty = salesQty;

 

 

 

 

 

 

_Client.update(_callContext, entityKeys, _SalesOrderList);

 

 

Delete method code

 


SalesOrderService.KeyField keyField = new SalesOrderService.KeyField() { Field = "SalesId", Value = "000757" };

 

 

 

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

 

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

 

 

 

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

 

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

 

 

 

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

 

 

 

 

 

SalesOrderService.SalesOrderServiceClient _Client = new SalesOrderService.SalesOrderServiceClient();

 

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

 

_callContext.Company = “USMF”;

 

_Client.delete(_callContext, entityKeys);

 

 

Trouble shooting AIF service.

There are many possible failure of sales service call, You can trouble shoot it from  System Administration section as

Exceptions

During writing code and I got many failures, All exceptions recorded here.

 

ExceptionsForm




Integration with dynamics Ax 2012 Session PPt and pictures.

October 10, 2014 by alirazazaidi

I did a session on Dynamics Ax 2012 at Lahore Microsoft Invocation Center at 30 September 2014. Session was wonderful. Much better the previous one, I am special thankful to Software gurus from various software companies join this and especially for Microsoft Invocation Center Management team that help me to conduct this session.

 
[slideshare id=39715072&doc=integrationwithdynamicsax2012-140930130108-phpapp01]

 

From System limited, Special thanks to Bashir Ahmed, Riaz Ahmad, Talha Majeed and all others who came from different Software houses.

 

List as data contract in Custom AIF service Dynamics Ax 2012

October 8, 2014 by alirazazaidi

During writing one of custom AIF services, I had requirement to get and set List of certain class type. For exampel Contact list if we have to import Customer or vendor, I found following syntax for attribute to make List as data contract.
[DataMemberAttribute(“MyContactList”),
AifCollectionTypeAttribute(“contactList”,Types::Class, classStr(ContactDC)),
AifCollectionTypeAttribute(“return”,Types::Class, classStr(ContactDC))]
public List parmMyContactList(List contactList =_contactList)
{
_contactList = contactList;
return _contactList;
}

“Wrong field ID in the key data container in entity key” Dynamics Ax 2012 AIF

September 17, 2014 by alirazazaidi

I got following Error when I called the Read method of Dynamics Ax AIF service.

“Wrong field ID in the key data container in entity key”

 

 

My code snippet is as follow and I did not found anything wrong with it.

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];

 

 

After trouble shooting I found that I was trying to read on field which have same value in multiple rows. For example I am trying to read from filed FirstName and value “Ali” exists more than one row.

 

It is recommend that read method will applied on column or field which have unique index.

I was working on testing data, so I delete the all records which have “Ali” value in “FirstName” field. Only one record left for value “Ali”. This time Read method works perfectly right.

It is recommended that if you have repeated values in different rows, you Find method of dynamics Ax 2012.

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


 

 

 

How to integrate Dynamics AX 2012 R3 AIF Document Service with BizTalk server

July 1, 2014 by alirazazaidi

Purpose: Purpose of this post is help to Consume AIF Document service in BizTalk and call its method.

Assumption: that target audience has deep knowledge of BizTalk, mapping, schema and orchestration.

 

First of all you have to create service group that is gateway to your document service. For this post I have to consume VendVendGroupService. I create a new service group  in AOT and drop VendVendGroupService to that node as follow

 

ServiceGroup

 

Right click and deploy the service group.

 

Deploy Service Group

 

 

Wait for generate Increment CIL and Infobox shows deployment of All possible Service group

VendorServiceGroupInfolog

 

Now to System Administration module of dynamics Ax. Click on System Administrationè Setup è Services and Integration frameworkè inbound port.

 

InBound Port

 

 

Now create a visual studio project for BizTalk. There are three sub solution, One for Schema, Map and third for orchestration.

 

In Schema solution. Add the generate Items and then select consume wcf Service

ConsumingAiFservice

 

Now add copy wsdl to generate Schemas.

Select metadata Exchange (MEX) endpoint

 

MetaData

 

 

Click next and generate schema

 

Schema Generation

 

Wsdl

 

 

Schema is generated.

 

VendorGroupSchema

 

Go to Schema project and delete the Vendor Group Service Orchestration.

 

 

Required Services

 

Important Schema which will used in mapping.

 

 

EntityKeyList Schema has following fields which are used to set values in Request response methods.

 

Entity List Schema

 

This key value pair used for search , Field represent table field Name and value is search field.

 

VendorGroupSchemaDetail

 

VendorGroup schema is replicate of VendorGroup table, here we use SenderId is used legal entity where operation will perform.

 

If we see the Service Schema, here all request and response methods are generated.

 

ServiceSchema

 

 

One Schema I create to take input to Interface, and decide which operation is performed I called it for InputSchema.

 

CustomSchema

 

This Schema will use for input to Interface. We will discuss it later when we start mapping one by one.

 

 

Bindings:

As compare to other wcf service, when we consume wcf service, empty binding files are generated, so we have create binding operations manually.

These operations are based on AIF service Object not AIF service Group, where I wasted hours on it.

Please consider the following screenshot for Service operations used in binding files.

ServiceOperations

 

The operations in BtsAction will be generated as follow.

Namespace +/+ExternalName+”/”+method name. All Action are similar. For example

 

http://WIN-IKPOSIU2SGD:8101/DynamicsAx/Services/VendorGroupService/read.

 

Settings for BizTalk Send Receive port is as follow.

 

NetTCPBindings

 

 

Pipeline settings:

Send Pipeline should be XML Transmit.

Receive Pipeline should be XML Receive.

Click on Configure Button and set as following.

 

WCF Settings.

 

Remember the Operation Name in SOAP action header mast be identical to Operation Name in logical port in Orchestration.

1234

 

All action mapping is as follow.

 

<BtsActionMapping xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">

<Operation Name="ReadOP" Action="http://schemas.microsoft.com/dynamics/2008/01/services/VendGroupService/read" />

<Operation Name="CreateOP" Action="http://schemas.microsoft.com/dynamics/2008/01/services/VendGroupService/create" />

<Operation Name="UpdateOP" Action="http://schemas.microsoft.com/dynamics/2008/01/services/VendGroupService/update" />

<Operation Name="DeleteOP" Action="http://schemas.microsoft.com/dynamics/2008/01/services/VendGroupService/delete" />

<Operation Name="FindOP" Action="http://schemas.microsoft.com/dynamics/2008/01/services/VendGroupService/find" />

</BtsActionMapping>

Mappings:

I attached  screenshots for mapping used for calling AIF methods.

 

Read Method:

 

Read method is two-step process, first step map the input to Entity list, and then Entity list  to VendGroupReadRequest

 

 

Input_To_EntityList

 

Entitylist_to_VendGroupRequestRead

 

 

Create Method:

In the case of Create Mapping is as follow.

 

InputSchema_to_VendorGroup

 

VendorGroup_to_CreatVendorGroupRequest

 

Delete Method:

 

EntityList_To_DeleteRequest

 

 

 

Update Method:

Update is little tricky, There is field in Update Request Schema, _DocumentHASH, This Field is hidden and every row has its unique value, without that row is did not updated. According to Microsoft Documentation, First you get /find required record using read or find method and then use response data to Update it. For saving time and for the sake of this tutorial, I just pic the_docuemntHash key form previously read response method and hardcode it in map. This is not generic way, but this solve the temporary and my wants to run the Update AIF document method.

 

FindMessage

 

 

Find method:

Find method is works wonder, if you want to search more than one or all records you can call Find method, where is field with Operation, where you can mentions, value Equal, not equal, greater then equal etc. I want to get all vendor group from Dynamics In response, so I sent its value “not equal”. Response message return all values.

 

FindMessage

 

The code of this tutorial is attached, you can download it from here.


Short introduction to AIF framework

January 5, 2014 by alirazazaidi

Usually we have to communicate with external systems with Dynamics Ax. In many business Scenario, Data is imported from other application or export form Dynamics Ax to external system. For Data Export or import Microsoft provide AIF or application Integration Framework. Consider the following Business scenarios in which Microsoft Dynamics Ax accesses information that is managed in external applications.
The arrows indicate the direction in which requests flow.

AIF
AIF

What can we do with Dynamics AX Aif Services.
• Encapsulate the Business Logic.
• Communicate with external systems.
Encapsulate the Business logic:
With the help of Microsoft Dynamics Ax services framework, we can encapsulate required business logic. For example we can create sales order, purchase order, Create Customers, vendors. These custom business logic will be publish as web service through the Application Integration Framework (AIF). AIF also participate in any Service Oriented architecture (SOA).
Communicate with external systems.
Microsoft Dynamics AX Application Integration Framework (AIF) enables companies to integrate and communicate with other systems (External Systems). This communication is based on external business processes and partners through the exchange of XML over various transport media.
AIF enables Dynamics Ax to integrate Business to business or application to application scenario.

AIF Documents
AIF provides this capabilities by enabling the exchange of data through formatted XML known as Document. These Document contains both data and business logic. These Documents are based on a document class and these document classes are defined by using Microsoft Dynamics AX.
AIF framework supports both synchronous and asynchronous transports.
In Synchronous mode, requests are tightly coupled to response. This means that submitter of request must wait for a response from AIF before processed.
In asynchronous mode, request are placed into a queue. Called the gateway queue. These queued messages are processed later time and AIF sends a response later.
Inbound exchange. AIF can be used to send data into Microsoft Dynamics AX.
Out bound exchange. AIF can also be used to retrieve data from Microsoft Dynamics Ax. This kind of exchange is called outbound exchange.

Dynamics Ax 2012 : Exploring the Query Service

January 9, 2013 by alirazazaidi

You can excess AOT query directly in your dot .net code. For this purpose I predefine AIF services comes with dynamics ax 2012. These services return data in dataset and paging mechanism you can handle large sum of data set. I my last example I create a student table with following fields.

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

. To test the query services first we create a custom AOT services on Student table. For example I create a very simple query as following screen.
AOT Static Query

You can access query service with following url
http://[HostName]/DynamicsAx/Services/QueryService

After that I create a console application in visual studio to get dataset by calling Dynamics AOT static query in dot net code with the help of AIF Query services.
You can add services reference as
Adding Reference

I am creating Query reference with Namespace of QueryServiceTest.

QueryService Reference is added

Now in console application’s main method we call Query service and provide it AotQueryName and pageing object as follow. I am trying to fetch all the records form my custom Student table.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;

namespace TestAIFQueryServices
{
class Program
{
static void Main(string[] args)
{

QueryServiceTest.QueryServiceClient _QueryClient = new QueryServiceTest.QueryServiceClient();
DataSet dataSet;
QueryServiceTest.Paging paging = null;

dataSet = _QueryClient.ExecuteStaticQuery("StudentQuery", ref paging);
foreach (DataRow dr in dataSet.Tables[0].Rows)
{

Console.WriteLine(dr["FirstName"].ToString() + " " + dr["FirstName"].ToString());

}
Console.ReadKey();

}
}
}

Exploring the little complex custom service in Dynamics Ax 2012

January 7, 2013 by alirazazaidi

In this example, we explore a complex custom services. Which perform a insert , update, delete and return all the records form table. If you interested in basics of custom services you have to visit my pervious post on this topic
http://tech.alirazazaidi.com/explore-the-custom-service-in-dynamics-ax-2012/.

 

For this example, I create a very simple custom table . This table contains following fields.

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

For Data contract we have to create a new class. On class declaration method you have to put the attribute with name like as [DataContractAttribute]

[DataContractAttribute]
class StudnetDC
{
str rollNumber;
str address;
date dateOfBirth;
str firstName;
str lastName;

}

For each field I have to declare a separate param method with are equivalent to C# or Vb.net property method like as We have to use again a attribute on each method [ DataMemberAttribute(‘Parameter Name’)]


[ DataMemberAttribute('Address')]
public str paramAddress(str _address=address)
{
address=_address;
return address;
}


[ DataMemberAttribute('Date of Birth')]
public date paramDateOfBirth(date _dateOfBirth=dateOfBirth)
{
dateOfBirth=_dateOfBirth;
return dateOfBirth;
}


[ DataMemberAttribute('First Name')]
public str paramFirstName(str _firstName=firstName)
{
firstName= _firstName;
return firstName;
}


[ DataMemberAttribute('Last Name')]
public str paramLastName(str _lastName=lastName )
{
lastName= _lastName;
return lastName;
}


[ DataMemberAttribute('RollNumber')]

public str paramRollNumber(str _rollNumber= rollNumber)
{
rollNumber= _rollNumber;
return _rollNumber;
}

Then I create a service class. On each method I have to use attributes for passing parameter to method in my case, insert method will take parameter of contract class as follow.


[SysEntryPointAttribute(true),
AifCollectionTypeAttribute('Studentobj', Types::Class)]

public void InsertStudent(StudnetDC Studentobj)
{

Student studentbuf;
studentbuf.RollNumber = Studentobj.paramRollNumber();
studentbuf.FirstName = Studentobj.paramFirstName();
studentbuf.LastName = Studentobj.paramLastName();
studentbuf.DateOfBirth = Studentobj.paramDateOfBirth();
studentbuf.Address = Studentobj.paramAddress();
studentbuf.insert();

}

 


[SysEntryPointAttribute(true),
AifCollectionTypeAttribute('Studentobj', Types::Class)]
public void UpdateStudent(StudnetDC Studentobj)
{

Student studentbuf;

while select forUpdate studentbuf
where studentbuf.RollNumber== Studentobj.paramRollNumber()
{
studentbuf.RollNumber = Studentobj.paramRollNumber();
studentbuf.FirstName = Studentobj.paramFirstName();
studentbuf.LastName = Studentobj.paramLastName();
studentbuf.DateOfBirth = Studentobj.paramDateOfBirth();
studentbuf.Address = Studentobj.paramAddress();

}

}



[SysEntryPointAttribute(true),
AifCollectionTypeAttribute('Studentobj', Types::Class)]

public void DeleteStudent(StudnetDC Studentobj)
{

Student studentbuf;

while select forUpdate studentbuf
where studentbuf.RollNumber== Studentobj.paramRollNumber()
{
studentbuf.delete();

}

}

To return a list form Class method we have to use following attribute on method.
[SysEntryPointAttribute(true),
AifCollectionTypeAttribute(‘return’, Types::Class, classStr(MyParam))]

[SysEntryPointAttribute(true),
AifCollectionTypeAttribute('return', Types::Class, classStr(StudnetDC))]
public list SelectStudent()
{
StudnetDC studentobj;
List _StudentList = new List(Types::Class);
Student studentbuf;
while select * from studentbuf

{
studentobj = new StudnetDC();
studentobj.paramFirstName( studentbuf.FirstName);
studentobj.paramLastName(studentbuf.LastName);
studentobj.paramRollNumber(studentbuf.RollNumber);
studentobj.paramAddress(studentbuf.Address);
studentobj.paramDateOfBirth(studentbuf.DateOfBirth);
_StudentList.addEnd(studentobj);

}
return _StudentList;
}

Now compile the both classes. Service node.

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