External Code unique value limitation D365FO
Out of the box, D365FO provides External codes feature to capture external references for Customers and Vendors. This could be an external system reference of Customer or Vendor accounts. Standard D365FO External codes data model limits an external code value to be linked to only one account per type - meaning when customer "C0001" has an external code "MemberId" with value "M0001", system will not allow another customer "C0002" to have external code "MemberId" with value "M0001". This limitation is implemented at the table index level.
However, there will be scenarios where the business requires same external code value to be allocated to multiple customer accounts. One such is multiple customer accounts linked to one dealer or some businesses having multiple accounts for same customer segregated by state or other criteria. In such cases, the out of the box index limitation will not allow same external code value to be allocated to multiple customer or vendor accounts.
Fortunately, the limiting index was built on "ExtCodeValueAlias" field which holds copied value of "ExtCodeValue" field, along with fields "ExtCodeId", "ExtCodeTableTableId" and "ExtCodeSubModule".
Using table event handlers "OnInserting" and "OnUpdating" on "ExtCodeValueTable", we can append the "ExtCodeValueAlias" with record Id of the customer or vendor to which the external code value is linked. That way, the external code value can be shared by multiple customer or vendor accounts for the same external code Id.
public final class NDSExtCodeValueTable_T_EventHandler
{
[DataEventHandler(tableStr(ExtCodeValueTable), DataEventType::Inserting)]
public static void ExtCodeValueTable_onInserting(Common sender, DataEventArgs e)
{
ExtCodeValueTable locExtCodeValueTable = sender as ExtCodeValueTable;
locExtCodeValueTable.ExtCodeValueAlias += '_' + int642Str(locExtCodeValueTable.ExtCodeRelationRecId);
}
[DataEventHandler(tableStr(ExtCodeValueTable), DataEventType::Updating)]
public static void ExtCodeValueTable_onUpdating(Common sender, DataEventArgs e)
{
ExtCodeValueTable locExtCodeValueTable = sender as ExtCodeValueTable;
ExtCodeValueTable origExtCodeValueTable = locExtCodeValueTable.orig();
if (locExtCodeValueTable.ExtCodeValue != origExtCodeValueTable.ExtCodeValue)
{
locExtCodeValueTable.ExtCodeValueAlias += '_' + int642Str(locExtCodeValueTable.ExtCodeRelationRecId);
}
}
}
Comments
Post a Comment