Microsoft Dynamics AX Support

This blog contains posts by the Microsoft Dynamics AX Support Teams Worldwide

How to link the Purchase order line with a Vendor invoice line in the AIF VendVendInvoiceService service.

I have seen this issue come up several times so I thought a little blog article would be helpful to the Dynamics AX developers working with this AIF service.

When creating a Vendor Invoice using the VendVendInvoiceService service, you may have a business requirement to associate the Vendor invoice line with a Purchase order line. The service is not going to automatically retrieve or know which line to use based on just the Purchase Order number that you provide. So you need to provide the ID for that Purchase order line which is the InventTransId property.  The InventTransId on the VendInvoiceInfoLine table matches the InventTransId of the PurchLine table.

C# Example

This Console Application example shows how to reference the Purchase order line. I had created a Receipt for this Purchase order so I am referencing the Receipt in the VendInvoiceInfoSubLine also:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using VendServiceTester.AccountsPayableServices;


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

            VendVendInvoiceServiceClient client = new VendVendInvoiceServiceClient();
            CallContext context = new CallContext();
            context.Company = “USRT”;


            AxdVendInvoice vendInvoice = new AxdVendInvoice();
            AxdEntity_VendInvoiceInfoTable vendInvoiceInfoTable = new AxdEntity_VendInvoiceInfoTable();


            vendInvoiceInfoTable.CurrencyCode = “USD”;
            vendInvoiceInfoTable.InvoiceAccount = “1001”;
            vendInvoiceInfoTable.OrderAccount = “1001”;
            vendInvoiceInfoTable.Num = “AIF412”;
            vendInvoiceInfoTable.PaymMode = “USAUSD_CHK”;
            vendInvoiceInfoTable.PurchId = “001568”;
            /* Setting a PO number for an associated PO for PurchId creates an error
             * if vendInvoiceInfoLine.InventTransId is not set below.
             * INVENTTRANSID in vendInvoiceInfoLine matches to the PURCHLINE.INVENTTRANSID value


            AxdEntity_VendInvoiceInfoSubTable vendInvoiceInfoSubTable = new AxdEntity_VendInvoiceInfoSubTable();
            AxdEntity_VendInvoiceInfoLine vendInvoiceInfoLine = new AxdEntity_VendInvoiceInfoLine();
            AxdEntity_VendInvoiceInfoSubLine vendInvoiceInfoSubLine = new AxdEntity_VendInvoiceInfoSubLine();


            vendInvoiceInfoLine.OrderAccount = “1001”; // Vendor account
            vendInvoiceInfoLine.ItemId = “0001”; // Inventory Item
            vendInvoiceInfoLine.PurchInvoiceLineType = AxdEnum_PurchInvoiceLineType.Standard;
            vendInvoiceInfoLine.PurchInvoiceLineTypeSpecified = true;
            vendInvoiceInfoLine.ReceiveNow = 1; // QTY in AX Form
            vendInvoiceInfoLine.PurchPrice = 41.99M; //Unit Price in AX Form
            vendInvoiceInfoLine.PurchPriceSpecified = true;
            vendInvoiceInfoLine.InventTransId = “00161642_068”;


            // VendInfoInfoSub Tables…
            vendInvoiceInfoLine.VendInvoiceInfoSubLine = new AxdEntity_VendInvoiceInfoSubLine[1] { vendInvoiceInfoSubLine };
            vendInvoiceInfoSubLine.DocumentId = “RCT000412”; // Receipt Number
            vendInvoiceInfoSubLine.ReceiveNow = 1;


            vendInvoiceInfoSubTable.VendInvoiceInfoLine = new AxdEntity_VendInvoiceInfoLine[1] { vendInvoiceInfoLine };
            vendInvoiceInfoSubTable.OrigPurchId = “000412”;
            vendInvoiceInfoTable.VendInvoiceInfoSubTable = new AxdEntity_VendInvoiceInfoSubTable[1] { vendInvoiceInfoSubTable };
            vendInvoice.VendInvoiceInfoTable = new AxdEntity_VendInvoiceInfoTable[1] { vendInvoiceInfoTable };


                client.create(context, vendInvoice);
            catch (Exception ex)


If you do not set the InventTransId property when passing in a Purchase order number value, you may receive AIF exceptions like these returned:

Item 0001 on invoice AIF412 line  is different from purchase order line item .

The item’s inventory model policy must be not stocked.