# AIF Integration in AX 2012: Inbound Sales Order Message Generator for the File System Adapter

> Source: https://netray.co/tools/ax-2012-aif-file-adapter-inbound-message-generator
> Publisher: Netray (netray.co), AI and integration engineering for ERP and manufacturing systems.
> Section: Free Tools

## Short answer

Fill in customer, PO reference, item, quantity, site and warehouse to get a ready-to-drop AIF envelope for SalesOrderService create, with the AIF batch tasks and troubleshooting steps.

## Category

microsoft-dynamics

## Erp

Microsoft Dynamics AX 2012

## Audience

- AX technical consultant
- Integration developer
- ERP administrator

## Tool

**Kind:** template

**Output:** code

**Language:** xml

**Fields:**

#### MessageId (new GUID every file)

**Key:** message_id

**Type:** text

**Default:** {7B1E3C52-9A4D-4F0B-8E21-5C6D9A0F3B17}

#### Target company (DataAreaId)

**Key:** company

**Type:** text

**Default:** usmf

#### Customer account

**Key:** cust_account

**Type:** text

**Default:** US-001

#### Customer PO number

**Key:** purch_order_ref

**Type:** text

**Default:** PO-7781

#### Requested receipt date

**Key:** delivery_date

**Type:** date

**Default:** 2026-11-15

#### Item number

**Key:** item_id

**Type:** text

**Default:** 1000

#### Quantity

**Key:** qty

**Type:** number

**Default:** 25

#### Sales unit

**Key:** sales_unit

**Type:** text

**Default:** ea

#### Site (InventSiteId)

**Key:** site

**Type:** text

**Default:** 1

#### Warehouse (InventLocationId)

**Key:** warehouse

**Type:** text

**Default:** 11

**Blocks:**

#### SalesOrderService create message (save as SO_0001.xml in the inbound folder)

**Body:** <?xml version='1.0' encoding='utf-8'?>
<Envelope xmlns='http://schemas.microsoft.com/dynamics/2011/01/documents/Message'>
  <Header>
    <MessageId>{{message_id}}</MessageId>
    <Company>{{company}}</Company>
    <Action>http://schemas.microsoft.com/dynamics/2008/01/services/SalesOrderService/create</Action>
  </Header>
  <Body>
    <MessageParts>
      <SalesOrder xmlns='http://schemas.microsoft.com/dynamics/2008/01/documents/SalesOrder'>
        <SalesTable class='entity'>
          <CustAccount>{{cust_account}}</CustAccount>
          <DeliveryDate>{{delivery_date}}</DeliveryDate>
          <PurchOrderFormNum>{{purch_order_ref}}</PurchOrderFormNum>
          <ReceiptDateRequested>{{delivery_date}}</ReceiptDateRequested>
          <SalesLine class='entity'>
            <ItemId>{{item_id}}</ItemId>
            <SalesQty>{{qty}}</SalesQty>
            <SalesUnit>{{sales_unit}}</SalesUnit>
            <InventDim class='entity'>
              <InventLocationId>{{warehouse}}</InventLocationId>
              <InventSiteId>{{site}}</InventSiteId>
            </InventDim>
          </SalesLine>
        </SalesTable>
      </SalesOrder>
    </MessageParts>
  </Body>
</Envelope>

#### Processing checklist

**Body:** 1. Inbound port: System administration > Setup > Services and Application Integration Framework > Inbound ports. Adapter = File system adapter, URI = the inbound folder, Response address = an outbound folder. Service operation SalesSalesOrderService.create selected. Port activated.
2. Data policies: Customize documents > Data policies. Enable CustAccount, ItemId and every element you send (DeliveryDate, PurchOrderFormNum, ReceiptDateRequested, SalesQty, SalesUnit, InventDim/InventSiteId, InventDim/InventLocationId).
3. Batch job: System administration > Inquiries > Batch jobs > Batch jobs. One recurring job with four tasks: AifGatewayReceiveService, AifInboundProcessingService, AifOutboundProcessingService, AifGatewaySendService. Status Waiting; a 1 minute recurrence is convenient for testing.
4. Drop the file. Files are processed in file name order, so name them SO_0001.xml, SO_0002.xml.
5. Check the response file in the outbound folder: a SalesId in EntityKeyList means the order was created; RequestMessageId equals {{message_id}}.
6. If nothing appears: System administration > Periodic > Services and Application Integration Framework > Queue manager (message status) and Exceptions (error text, for example a disabled data policy element or an unknown item).

**Notes:** Verify on your system: the namespaces are http:// URIs and must match exactly. Header Company must be a company the port allows (or remove it to use the port or submitting user default). Elements inside each entity follow the schema sequence, which for the sales order document is field names in alphabetical order followed by child entities, so keep InventDim after the SalesLine fields and InventLocationId before InventSiteId. Download the schema from the port (Document data policies or the service WSDL) to confirm. Use a new GUID in MessageId for every file; AIF rejects duplicates.

## Content

**Intro:** This generator builds an AIF inbound XML message for the SalesOrderService create operation in Dynamics AX 2012, ready to drop into the folder of an enhanced inbound port that uses the file system adapter. A second block lists the port, data policy and batch settings and where to look when the order does not appear.

**Sections:**

#### How to use it

**Body:** Generate a fresh GUID for MessageId (PowerShell: [guid]::NewGuid()), fill in a real customer account, item, unit, site and warehouse for the target company, and copy the XML into a UTF-8 file. Save it to the inbound folder configured on the port. Within one or two batch cycles AX picks up the file, creates the sales order and writes a response with the new SalesId to the response folder. To send more orders, change MessageId and the values, and name files in sequence because the adapter processes them in file name order.

#### Where this lives in AX 2012

**Body:** Enhanced integration ports live under System administration > Setup > Services and Application Integration Framework > Inbound ports. The file system adapter is asynchronous, so messages wait in the AIF queue until the AIF batch tasks run: AifGatewayReceiveService reads the folder, AifInboundProcessingService calls the service, AifOutboundProcessingService builds the response and AifGatewaySendService writes it out. Message status is in the Queue manager and errors in Exceptions, both under System administration > Periodic > Services and Application Integration Framework.

**Bullets:**

- Service operation: SalesSalesOrderService.create
- Document: SalesOrder with SalesTable and SalesLine entities
- Each element sent must be enabled in Data policies
- Response correlates through RequestMessageId

#### Worked example

**Body:** Customer US-001 sends PO-7781 for 25 ea of item 1000, wanted on 2026-11-15 from site 1 warehouse 11. The generated file sets CustAccount US-001, PurchOrderFormNum PO-7781 (the customer requisition shown on the order), ReceiptDateRequested and DeliveryDate 2026-11-15, and one SalesLine with InventDim site and warehouse. After processing, the response contains KeyField SalesId with the new order number. Opening Accounts receivable > Common > Sales orders shows the order with the customer reference filled in.

#### Version differences and gotchas

**Body:** The envelope namespace is 2011/01 while the service action and document namespaces are 2008/01; mixing them up is the most common cause of a silent failure. Required fields and defaults depend on the port's document data policy and the customer and item setup; if the item uses product dimensions such as configuration or size, add those InventDim elements and enable them. In AX 2012 R2 and R3 partitions apply; a port restricted to one company or partition rejects messages for others. Duplicate MessageId values are rejected, so never reuse a file.

**Cta:** If you want a private AI assistant that drafts and validates AIF messages or answers questions about your AX 2012 orders on your own servers, we can set that up.

**Faq:**

#### How does AIF integration work in AX 2012?

**Answer:** An integration port exposes service operations such as SalesSalesOrderService.create through an adapter: file system, MSMQ, BizTalk or web services. Asynchronous adapters such as the file system adapter put messages in the AIF queue, and four AIF batch tasks receive, process, build responses and send them. Data policies control which XML elements are accepted.

#### What XML format does AX 2012 AIF expect for a sales order?

**Answer:** An Envelope in the 2011/01 Message namespace with a Header (MessageId and Action) and a Body containing MessageParts. Inside is a SalesOrder document in the 2008/01 SalesOrder namespace with SalesTable and nested SalesLine entities, each marked class='entity'. This tool generates that structure.

#### Why is my AIF file not picked up from the folder?

**Answer:** Usually the batch job is not running or lacks the AifGatewayReceiveService task, the port is not activated, or the AOS service account cannot read the folder. Check the batch job status, the port, and folder permissions for the AOS account. Then check Queue manager and Exceptions for messages that were read but failed.

#### Can I reuse the same MessageId?

**Answer:** No. AIF uses MessageId to detect duplicates and will reject a message whose ID was already processed. Generate a new GUID for every file. The response carries your MessageId in RequestMessageId so the sending system can match responses to requests.

## Search terms

aif integration in ax 2012, ax 2012 aif file system adapter, ax 2012 aif sales order xml, salesorderservice create xml, ax dynamics erp integration, ax 2012 aif inbound port, dynamics ax dynamics 365 integration

---
Talk to an engineer: https://netray.co/contact?intent=erp_ai | Machine catalog: https://netray.co/agent/catalog.json
