Get all financial dimension value and description from DimensionAttribute

Capture

static void TIDF_getDimensionValue(Args _args)
{
    DimensionAttribute              dimAttr;
    DimensionAttributeViewContract  dimAttrViewContract;
    Query                           q;
    QueryRun                        qR;
    QueryBuildDataSource            qbds;
    Common                          common;

    dimAttr = DimensionAttribute::findByName("1. STORE");


    dimAttrViewContract =  DimensionAttribute::getViewContract(dimAttr.RecId);

    q = new Query();

    changecompany (dimAttr.company())
    {
        qbds = q.addDataSource(dimAttrViewContract.parmViewId());
        qbds.addSortField(dimAttrViewContract.parmValueFieldId(),SortOrder::Ascending);

         // Apply ranges on language ID fields.
        DimensionAttribute::addTranslViewRangesToBackingEntityQuery(dimAttr.RecId, qbds);

        if (DimensionCache::instance().dimensionAttributeHasCategorization(dimAttr.RecId))
        {
            if (dimAttr.Type == DimensionAttributeType::MainAccount)
            {
                qbds.addRange(dimAttrViewContract.parmCategoryFieldId()).value(queryValue(LedgerChartOfAccounts::current()));
            }
            else if (dimAttr.Type == DimensionAttributeType::CustomList)
            {
                qbds = qbds.addDataSource(tablenum(DimensionAttributeDirCategory), 'DimAttDirCat');
                qbds.relations(true);
                qbds.joinMode(JoinMode::InnerJoin);
                qbds.fetchMode(QueryFetchMode::One2One);
                qbds.addLink(dimAttrViewContract.parmCategoryFieldId(), fieldnum(DimensionAttributeDirCategory, DirCategory));
                qbds.addRange(fieldnum(DimensionAttributeDirCategory, DimensionAttribute)).value(strfmt('%1', dimAttr.RecId));
            }
        }
    }

    qR = new QueryRun(q);
    while(qR.next())
    {
        common = qR.get(dimAttrViewContract.parmViewId());

        info(strFmt("%1 %2",common.getFieldValue(dimAttrViewContract.parmValueFieldName()), common.getFieldValue(dimAttrViewContract.parmNameFieldName())));
    }

}
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s