Contents

Insert, update, Delete order line through AIF In AX 2012 R3

Contents

In previous post, I already show how to create purchase order through AIF with NETTCP or HTTP adapter. In this post, we will get little deep more about action on line of order.

The following code sample shows how to insert, update, delete a line of an existing purchase order through AIF, currently I’m using C#.NET console project for demo.

As Partial update, we must include just the fields to change and any fields required by the document (you can check Data policies in AIF Service ports form for that).

Also, notice how action properties are specified – no matter we do with the line, which means updating the order.

I’m giving you an idea how it looks like, here is the code

The first method will handle the key of AIF Service

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
private static EntityKey[] EntityForPurchId(string purchId)
{
	KeyField field = new KeyField()
	{
		Field = "PurchId",
		Value = purchId
	};

	EntityKey key = new EntityKey()
	{
		KeyData = new[] { field }
	};

	return new[] { key };
}

create Line, delete Line, update line in Purchase order

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
EntityKey[] entityKeyList = EntityForPurchId("BGR-000054");

CallContext callContext = new CallContext();
callContext.Company = "bgr";

Mav_PurchOrderServiceServiceClient client = new Mav_PurchOrderServiceServiceClient();
AxdMav_PurchOrderService purchOrders = client.read(callContext, entityKeyList);

//Define which line need to be update or delete
var lastLine = purchOrders.PurchTable[0].PurchLine.Last();

var purchLine = new AxdEntity_PurchLine()
{
	ItemId = "110329",
	PurchQty = 1,
	CurrencyCode = "KRW",
	RecIdSpecified      = true,
	LineNumberSpecified = true,
	action              = AxdEnum_AxdEntityAction.create,
	actionSpecified     = true

	//for delete
	//RecId               = lastLine.RecId,
	//RecIdSpecified      = true,
	//action              = AxdEnum_AxdEntityAction.delete,
	//actionSpecified     = true

	//for Update
	//RecId               = lastLine.RecId,
	//RecIdSpecified      = true,
	//action              = AxdEnum_AxdEntityAction.update,
	//actionSpecified     = true
	
};

var purchTable = new AxdEntity_PurchTable()
{
	_DocumentHash = purchOrders.PurchTable[0]._DocumentHash,
	OrderAccount = "101-01-75441",
	LanguageId = "en-us",
	CurrencyCode = "KRW",
	PurchName = "AIF PO Test",
	action = AxdEnum_AxdEntityAction.update,
	actionSpecified = true,
	PurchLine = new[] { purchLine }
};

AxdMav_PurchOrderService purchOrder = new AxdMav_PurchOrderService()
{
	PurchTable = new AxdEntity_PurchTable[] {purchTable}
};


client.update(callContext, entityKeyList, purchOrder);

Thank you for reading!