0% found this document useful (0 votes)
307 views

How To Add Extension Methods To Commerce Data Exchange Real-Time Service

The document discusses how to add extension methods to the Commerce Data Exchange: Real-time Service in Dynamics AX. It describes how to add an extension method in the AX RetailTransactionServiceEx class, ensuring it meets requirements. It also explains how to call these extension methods from a CRT client using the InvokeExtensionMethod method similarly to normal service methods. An example is provided of an extension method that returns a greeting message for a customer, and how to call it from the client.

Uploaded by

Islam Sultan
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
307 views

How To Add Extension Methods To Commerce Data Exchange Real-Time Service

The document discusses how to add extension methods to the Commerce Data Exchange: Real-time Service in Dynamics AX. It describes how to add an extension method in the AX RetailTransactionServiceEx class, ensuring it meets requirements. It also explains how to call these extension methods from a CRT client using the InvokeExtensionMethod method similarly to normal service methods. An example is provided of an extension method that returns a greeting message for a customer, and how to call it from the client.

Uploaded by

Islam Sultan
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

How to Add Extension Methods to Commerce Data Exchange: Real-time Service

Commerce Data Exchange: Real-time Service Overview


Commerce Data Exchange: Real-time Service enables the retail clients, from POS to SharePoint StoreFront, to interact with AX retail functionalities in real-time. Client

AX Object Server

Commerce Data Exchange: Real-time Service

Client

Client AX Database Client

The Real-time Service by default allows the client to perform the following operations by default (not limited to the list): Issue/query/use gift card Query/update/use loyalty points Issue/query/use credit memo Create/query/update customer information Create/query/retrieve customer orders, sales orders, transfer orders etc. Query/retrieve existing transactions Return transactions/items Remote staff log on/ log off, clock in/ clock out

Extension Overview
In addition to the default functionality that ships with the product, the Real-time Service also allows customers and partners to extend its functionality by adding extension methods. These methods can be invoked from the client side to perform any custom business logic.

Note that in order for the extension methods to work, the Real-time Service must be installed and configured correctly. Please see the documentation on Install and configure Commerce Data Exchange: Real-time Service <Add link> for details on how to do that. The rest of the document will describe how to add extension methods in AX, and how to consume the extension methods from a CRT client.

How to Add Extension Methods in AX


Pre-requisites: Dynamics AX 2012 R2 installed. Developer license for Dynamics AX 2012 R2.

How to add extension methods in AX: Adding extension methods in AX is very straightforward. You just need to add a new method in the RetailTransactionServiceEx class in the AOT. There are a few requirements for this method so that it can be invoked through the Real-time Service: The method must be a public static method. The return type must be a container of length 2 or longer. The first two elements are reserved for a Boolean indicating success/failure of the method call, and a string that can be used for comment or error message. The other items in the returned container can be of any type, including nested containers. The parameters for the method must be of primitive types in AX. Only the following types are supported due to BC.NET limitations:
CLR type
System.Boolean System.DateTime System.Int32 System.Int64 System.String System.Guid System.Single or System.Double

X++ type
boolean date int int64 str guid Real

Example: We would like to add a method that accepts a customer account number, and returns a greeting message with the customer name. For example, say we have customer Sandy whose account number is 1001, the method would return Hello Sandy! The AX side implementation is to add the following method in RetailTransactionServiceEx class:
public static container Hello(AccountNum accountNumber) { CustTable custTable; DirPartyTable dirPartyTable; container result = [false, '']; if (accountNumber) { select firstOnly Name from dirPartyTable exists join custTable where custTable.accountNum == accountNumber && dirPartyTable.RecId == CustTable.Party; if (dirPartyTable) { result = [true, 'Success!', strFmt("Hello %1 !", dirPartyTable.Name)]; } else { result = [false, 'Customer not found']; } } else { result = [false, 'accountNumber is null.']; } return result; }

Consuming the Extension Methods from CRT Client


Consuming the Real-time Service extension methods from CRT client is also very straightforward. It is very similar to consuming the normal Real-time Service methods. The only difference is that instead of calling InvokeMethod, we need to call InvokeExtensionMethod. Here is an example of calling the Hello methods we showed as example in the previous section:
public void HelloCustomer(string accountNumber) { try { var response = this.CommerceRuntime.TransactionService.InvokeExtensionMethod("Hello", "2014"); if (response.Count == 1) { Console.WriteLine(response[0] as string); } } catch (CommunicationException ex) { Console.WriteLine("Request failed: {0}", ex.Message);

} }

Note that the response successful/comments have been abstracted away. If the request failed (false on the first container results), the service client will throw a communication exception. Only the additional response data is returned.

You might also like