Thursday, November 02, 2006

Custom Validation Modifications to AIF

Yesterday I was able to fully setup a custom validation within AIF. The validation was regarding ItemIds (Part Numbers) in AX. Out of the box, when the 'createListSalesOrder' action is executed on an inbound XML Sales Order, the entire process halts upon validation of an invalid ItemId (one that is not in the Item List (InventTable). I developed a workaround to check for the current ItemId's existence in the InventTable and if it's not present, replace the invalid ItemId with a valid catch-all ItemId, which will allow AIF to continue processing the Sales Order. So far this modification has been successful.

In general terms, you can make customizations to any of AIF's transactions simply by modifying the appropriate parm[field_name] method within the appropriate Ax[Table] class for the field that you want to add addition customizations on. In my example, I modified the parmItemId method within the AxSalesLine class. Here is the new parmItemId() method with my modification:

public str parmItemId(str _itemId = '')
DictField dictField;
ItemId tempItemId;
InventTable tempInventTable;

//My custom code to validate ItemId's existence in the Item Master and replace w/ 'InvalidItem' if not
tempItemId = _itemId;
SELECT FIRSTONLY ItemId FROM tempInventTable WHERE tempInventTable.ItemId == tempItemId;
if (tempInventTable.ItemId != _itemId)
_itemId = "**INVALIDITEM**";
salesLine.ItemId = _itemId;
salesLine.Name = tempItemId;

if (!prmisdefault(_itemId))
dictField = new DictField(tablenum(SalesLine),fieldnum(SalesLine,ItemId));
if (this.valueMappingInbound())
item = _itemId;

this.setField(fieldnum(SalesLine, ItemId), _itemId);

if (this.valueMappingOutbound())
return conpeek(this.axSalesItemId(salesLine.CustAccount,salesLine.ItemId,salesLine.inventDim()),1);
return salesLine.ItemId;

Although this is my first shot at AIF modification, I would recommend placing your modification above the existing code. The out of the box code does other validations and checks like seeing whether or not AIF should place default data into a field.

Hope this helps!