Purpose:
The purpose of this post is to demonstrate how we can validate individual financial dimension values before writing a customer record.
Product:
Dynamics 365 for Finance and Operations
Description:
The code below validates some customer fields like Site, Warehouse, Price group and then checks the values for individual financial dimensions in this case which custom dimensions, Channel and Industry.
Code:
/// <summary> /// ValidatedWrite event handler /// </summary> /// <param name="sender"></param> /// <param name="e"></param> [DataEventHandler(tableStr(CustTable), DataEventType::ValidatedWrite)] public static void CustTable_onValidatedWrite(Common sender, DataEventArgs e) { #define.DimAttrNameChannel('Channel') #define.DimAttrNameIndustry('Industry') CustTable custTable = sender as CustTable; ValidateEventArgs event = e as ValidateEventArgs; DimensionAttributeValueSet dimensionAttributeValueSet; DimensionAttributeValueSetItem dimensionAttributeValueSetItem; DimensionAttributeValue dimensionAttributeValue; DimensionAttribute dimensionAttribute; DimensionAttributeValueSetStorage dimAttrValueSetStorage; boolean result = event.parmValidateResult(); if (!custTable.InventSiteId) { result = checkFailed(strFmt("Site is required.")); } if (!custTable.InventLocation) { result = checkFailed(strFmt("Warehouse is required.")); } if (!custTable.PriceGroup) { result = checkFailed(strFmt("Price is required.")); } if (!custTable.DefaultDimension) { result = checkFailed(strFmt("Financial dimensions Channel and Industry are required.")); } else { dimAttrValueSetStorage = DimensionAttributeValueSetStorage::find(custTable.DefaultDimension); dimensionAttribute = DimensionAttribute::findByName(#DimAttrNameChannel); if (!dimAttrValueSetStorage.containsDimensionAttribute(dimensionAttribute.RecId)) { result = checkFailed(strFmt("Financial dimensions Channel is required.")); } dimensionAttribute = DimensionAttribute::findByName(#DimAttrNameIndustry); if (!dimAttrValueSetStorage.containsDimensionAttribute(dimensionAttribute.RecId)) { result = checkFailed(strFmt("Financial dimensions Industry is required.")); } } event.parmValidateResult(result); }