Thursday, November 29, 2012

Get Financial Dimension Value from Worker Position

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");
}

How to identify the user that was used to change an object from AOT in AX2012

Get the object name for which we need to track these (user and date&time) information's. Login to SQL Server Management Studio an...