class DGS_CommonDimension
{
static DimensionDefault buildDimension(DimensionDefault olddimensionDefault, str dimensionName, DimensionValue newDimensionValue)
{
DimensionAttributeValueSetStorage dimensionAttributeValueSetStorage;
DimensionAttribute dimensionAttribute;
DimensionAttributeValue dimensionAttributeValue;
DimensionDefault dimensionDefault;
LedgerDimensionAccount ledgerDimensionAccount;
DimensionValue oldDimensionValue;
DimensionValue getDimensonValue(DimensionDefault _dimensionDefault)
{
DefaultDimensionView defaultDimensionView;
select firstonly DisplayValue
from defaultDimensionView
where defaultDimensionView.Name == dimensionName
&& defaultDimensionView.DefaultDimension == _dimensionDefault;
return defaultDimensionView.DisplayValue;
}
oldDimensionValue = getDimensonValue(olddimensionDefault);
// dimensionAttributeValueSetStorage = new DimensionAttributeValueSetStorage();
// Build DimensionAttributeValueSetStorage
dimensionAttributeValueSetStorage = DimensionAttributeValueSetStorage::find(olddimensionDefault);
// Remove old dimension value
dimensionAttribute = DimensionAttribute::findByName(dimensionName);
dimensionAttributeValueSetStorage.removeDimensionAttributeValue(
DimensionAttributeValue::findByDimensionAttributeAndValue(dimensionAttribute, oldDimensionValue).RecId);
// Set new dimension value
if(newDimensionValue != "")
{
dimensionAttribute = DimensionAttribute::findByName(dimensionName);
dimensionAttributeValueSetStorage.addItem(
DimensionAttributeValue::findByDimensionAttributeAndValue(dimensionAttribute, newDimensionValue));
}
dimensionDefault = dimensionAttributeValueSetStorage.save();
info(strFmt("Default dimension recId: %1", dimensionDefault));
return dimensionDefault;
}
}
====================================
/// <summary>
///
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
[DataEventHandler(tableStr(TMSSalesTable), DataEventType::ModifiedField)]
public static void TMSSalesTable_onModifiedField(Common sender, DataEventArgs e)
{
#define.dimensionName("ShippingCarrier")
TMSSalesTable tmsSalesTable = sender;
SalesTable salesTable = SalesTable::find(tmsSalesTable.SalesId) ;
ModifyFieldEventArgs modifyFieldEvent = e as ModifyFieldEventArgs;
DimensionAttributeValueSet _dimensionAttributeValueSet;
DimensionValue _value;
DimensionDefault newDimensionDefault ;
DimensionAttribute _dimensionAttribute;
DimensionAttributeValue _dimensionAttributeValue;
switch (modifyFieldEvent.parmFieldId())
{
case fieldNum(TMSSalesTable, CarrierServiceCode):
_value = tmsSalesTable.CarrierServiceCode;
if(_value)
{
_dimensionAttribute = DimensionAttribute::findByName(#dimensionName);
if(_dimensionAttribute && _value)
{
_dimensionAttributeValue = DimensionAttributeValue::findByDimensionAttributeAndValue(_dimensionAttribute,_value);
// if have this display value inside Financial Dimension, create a new dimensiont value set to salesTable
if(_dimensionAttributeValue)
{
newDimensionDefault = DGS_CommonDimension::buildDimension(salesTable.defaultDimension,#dimensionName,_value);
ttsbegin;
salesTable.selectForUpdate(true);
salesTable.DefaultDimension = newDimensionDefault;
salesTable.update();
ttscommit;
}
else
{
throw Error(strFmt("@SYS26332", #dimensionName));
}
}
else
{
throw Error(strFmt("@SYS26332", #dimensionName));
}
}
break;
}
}
}
留言列表