最新消息:ww12345678 的部落格重装上线,希望大家继续支持。

验证单个财务维度 / Validate individual financial dimensions

网络文摘 William 18浏览 0评论

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);
}
发表我的评论
取消评论

表情

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址