问题
My task is to add a field in VendOpenTrans with a specific Dimension. I have added to my DataSources in VendOpenTrans tables DimensionAttributeValueSet, DimensionAttributeValueSetItem, DimensionAttributeValue and DimensionAttribute.
In their properties I have made joins (join source) with InnerJoin LinkType (I tried all of the options here). Then I have add a field on my grid from DimensionAttributeValueSetItem -> DisplayValue (field name).
And now in ExecuteQuery method of VendOpenTrans I add a code:
public void executeQuery()
{
/*QueryBuildRange dimensionAttributeValueSetRange;
;
dimensionAttributeValueSetRange = this.query().dataSourceTable(tableNum(DimensionAttribute)).addRange(fieldNum(DimensionAttribute, Name ));
dimensionAttributeValueSetRange.value('MyDimensionName');
super();
}
The final result of this is that I have a new filter with my dimension. So I don't see on my grid records that have an empty value in this dimension.
The thing that I want to achieve is to show the value of "MyDimensionName" if It's filled but when It's not record should be shown with just an empty value...
I spend on this many many hours and I still didn't work it out...
回答1:
Selecting on specific dimension in AX 2012 is tricky beyond reason, but this method may be of help:
static void queryDimensionUpdate(LedgerDimensionAccount _dimension, Query _q, str _dataSourceName, FieldName _field = fieldStr(GeneralJournalAccountEntry,LedgerDimension))
{
DimensionStorageSegment segment;
DimensionStorage storage = DimensionStorage::findById(_dimension);
DimensionProvider provider = new DimensionProvider();
DimensionAttributeValue value;
Name name;
int segmentCount;
int s;
if (storage)
{
segmentCount = storage.segmentCount();
for (s = 1; s <= segmentCount; s++)
{
segment = storage.getSegment(s);
if (segment.parmDimensionAttributeValueId())
{
name = DimensionAttribute::find(DimensionAttributeValue::find(segment.parmDimensionAttributeValueId()).DimensionAttribute).Name;
//info(strFmt('%1: %2, %3', name, segment.parmDisplayValue(), segment.getName()));
provider.addAttributeRangeToQuery(_q, _dataSourceName, _field, DimensionComponent::DimensionAttribute, segment.parmDisplayValue(), name);
}
}
}
}
Given a _dimension
set with proper values to search for, say 011010-103-101--, it will update the query _q
selecting for the dimensions given (011010, 103 and 101 in the example) related to the datasource _datasourceName
and field _field
.
It does so by iterating _dimension
segments for values, then updating the query using the DimensionProvider.addAttributeRangeToQuery
method.
来源:https://stackoverflow.com/questions/31156695/specific-dimension-on-vendopentrans-grid