How to get Financial Dimension Value from Worker Position[AX2012]

To get financial dimension value from worker position, add a new method in hcmWorker Table with script like below:

public static str getDimensionValue
          (HcmWorkerRecId _workerRecId, 
           Name _DimensionName, 
           utcdatetime _asOfDate = DateTimeUtil::utcNow())
{
    DimensionAttributeValueSetStorage             dimStorage;
    str                                                             dimValue;
    Counter                                                     Counter;
    HcmPositionDefaultDimension                    _HcmPositionDefaultDimension;
    RecId                                                       _DefaultDimension;
    ;
    select _HcmPositionDefaultDimension where
    _HcmPositionDefaultDimension.Position == HcmWorker::getPrimaryPosition(_workerRecId);
    dimStorage = DimensionAttributeValueSetStorage::find
                         (_HcmPositionDefaultDimension.DefaultDimension);
    for (Counter=1 ; Counter<= dimStorage.elements() ; Counter++)
    {
         if(DimensionAttribute::find(dimStorage.getAttributeByIndex(Counter)).Name == _DimensionName)
         {
               dimValue = dimStorage.getDisplayValueByIndex(Counter);
         }
    }
    return dimValue;
}

After it, if we wanna make display method to show financial dimension, we can use method above. In example we wanna display dimension site from a worker who have PersonnelNumber = "00001". The script is like below :

display str Site()
{
          return hcmWorker::getDimensionValue(
                    hcmWorker::findByPersonnelNumber("00001").recid, "Site");
}

 

posted @ 2013-10-07 17:02  Fandy Xie  Views(1007)  Comments(0Edit  收藏  举报