Get Segments from Segment Entry Control in LedgerDimension

 

We can get the different segments present in segment entry control. In the below example i am using GL - Inquiries - Voucher transactions screen. 



On this screen lets try to get Main Account segment & display in the grid. Write a display method on GeneralJournalAccountEntry table. 


public display DimensionValue displayMainAcct()
{
    #define.MainAccount('MainAccount')
    DimensionStorage        dimensionStorage;
    int                     segmentCount, segmentIndex;
    DimensionStorageSegment segment;
    DimensionValue          segmentName, MainAccount, segmentValue, MainAcctValue;
    container               segments;


    dimensionStorage = DimensionStorage::findById(this.LedgerDimension);
    
    // Add segments for all hierarchies
    segments = conNull();

    // Get segments
    segmentCount = dimensionStorage.segmentCountForHierarchy(1);
    for (segmentIndex = 1; segmentIndex <= segmentCount; segmentIndex++)
    {
        // Get segment
        segment = dimensionStorage.getSegmentForHierarchy(1, segmentIndex);
        if (segment.parmDimensionAttributeValueId() != 0)
        {
            // Get segment name
            segmentName = DimensionAttribute::find(DimensionAttributeValue::find(segment.parmDimensionAttributeValueId        ()).DimensionAttribute).Name;

            // Add segment value
            segmentValue = segment.parmDisplayValue();

            if (segmentName == #MainAccount)
                MainAcctValue = segmentValue;

        }
    }

    return MainAcctValue;
}


Here is the result


Comments

Popular posts from this blog

Sales order invoice posting using X++ with custom SalesParmLine fields

Create a custom lookup with multiple data sources on form using X++

SalesTable2Line custom field update prompt on Sales order in AX 2012