Dynamics AX insists that the ItemID be used on the Sales Line portion of the Sales Order Form. Many companies, though, have vendors that place orders by barcode number, industry identifier, or even vendor-specific ID. Here is a bit of code that lets the user enter any other number in the Sales Order Form (Form SalesTable) and have Dynamics look up the corresponding ItemID.
This example just does a lookup on the InventItemBarcode table, but it could easily be adapted to (also/instead) check any other tables, (InventItemGTIN, ExtCodeTable, CustVendExternalItem) in order to find items by their GTIN, industry code, or customer/vendor specific item number.
I implemented the code on the SalesTable form, but you could easily adapt it to just about any other form that requires an Item ID.
Hope this helps!
public boolean validate()
{
/*
Overridden validate method. If number entered does not match an ItemID
this will look up the entry in the barcode table and return
the first ItemID that is associated with that barcode.
*/
boolean ret;
ItemId ItemId;
InventTable InventTable;
InventItemBarcode InventItemBarcode;
;
ret = super();
ItemId = this.text();
If (ItemID != "" && !InventTable::exist(ItemId))
{
InventTable = InventTable::find(InventItemBarcode::findBarcode(this.text(), False, False).itemId);
if (InventTable.ItemId != '')
{
info(StrFmt("Barcode lookup. Using Item ID: %1.",inventtable.ItemId)); //Optional
SalesLine.ItemId = InventTable.ItemId; // sets the field correctly
this.text(InventTable.ItemId); // suppresses error 'item not found in relating table'
}
}
return ret;
}