Consuming Pending Vendor invoice service from C#

This blog refers to consuming or creating Pending vendor invoice record in dynamics ax 2012 R3 using out of box service “VendVendInvoiceService”. The focus of this blog is .net C# side. In this example I took the complex case of creating Vendor invoice that linked to multiple PURCHASE ORDERS in received status.

This ADDHeader method insert record in VendInvoiceInfoTable, for this example I just filled the required ones.


This ADDLine method insert a line in VendInvoiceInfoLine table. this is helper method will be called from main executing point.


This is the main executing method, In this method I did initialization of required objects, make find call of two purchase order records using Purchase order service (You could do this by any way, hard coded or service call or through .net proxies). Here I am also making the call of AddHeader method to create the header record


Further on the same method, call AddLine to create Line record, Also specify the QTY that how much I want to invoice from the receiving, I did the same for both the purchase orders.


After composing complete message, making Create call to service


Amir (Happy Daxing)


Method: disableLockEscalation

SrsReportDataProviderPreProcess::disableLockEscalation Method [AX 2012]

I was working on a long duration report and the report was build using RDP class that extends with SrsReportDataProviderPreProcess. It is the normal report with set based inserts/updates in temp tables. I implemented the complete class with all business logic and now when I run the report I got error as below.

An exception occurred in the query metadata execution. The exception is Cannot select a record in XXX Tmp (XXXX).

Cannot select a record for update when the transaction is not started on the user connection attached. You need to begin transaction on the user connection first.

 after some research I came to know that it is lock escalation issues that are exhibited by preprocessing reports tables that are populated using set-based inserts, that means you can not reselect the records from Tmp table for further updates.

In my scenario I have to do some updates and selects also on Tmp tables as the business logic was quite complex. For my case the method server public static void disableLockEscalation(TableId _tableId) helps me allot as it disables the lock and allow me to update and selects the previously inserted records

AX Users using Powershell command

The following steps need to be performed within the Microsoft Dynamics AX 2012
Management Shell, which is the PowerShell with the AX PowerShell commands preloaded:

1. Open the Management shell.
‰‰ For Windows 8 or Windows Server 2012: Search for Management shell
and click on the result, Microsoft AX 2012 Management Shell
For Windows 7 or Windows Server 2008: Open Administration Tools from
the Windows Start menu and open Microsoft AX 2012 Management Shell

2. Create an AD user for Binary\Josh by using the following command:

New-AXUser -AccountType WindowsUser -AXUserId Josh -UserDomain
“Binary.local” -PartitionKey initial Enabled -UserName Josh
-Company HHF

3. Disable user Josh by using the following command:
Disable-AXUser –AXUserId Josh

4. Enable user Josh by using the following command:
Enable-AXUser –AXUserId Josh –Server Zeus

5. Make Josh the system administrator by using the following command:
Add-AXSecurityRoleMember –AxUserId Josh –AOTName SysAdmin

Number of months between two dates in Dynamics ax 2012

Recently I got a situation where I need to calculate the number of months between 2 dates, I found a built in method in dynamics ax 2012 that can be used.

noOfIntervals = intvNo(refDate, inputDate, intvScale::Month);

intvScale enumation have two values for months

If we provide the intvScale::Month then X++ ignores the year and assumes that month is calculated within one year.

If we provide the intvScale::YearMonth then X++ calculate the number of months between different years. Consider following example.

There is another way to Calculates the difference between two dates in month units in Dynamics ax 2012 using method InfAdjValidation_MX::monthDifference(FromDate _fromDate, ToDate _toDate)

%d bloggers like this: