Showing posts with label Financial Dimensions. Show all posts
Showing posts with label Financial Dimensions. Show all posts

Wednesday, 2 March 2016

Get or split values start and end from range in AX 2012

For example you provided range from 100 to 110 and want both start and end value in some variable then you can use container to split range values.

static void GetSplitValuesFromRange(Args _args)
{
    str                 range;
    str                 startValue,endValue;
    List               ledgerRange = new list(Types::String);
    ListIterator    listIterator;
    container       con;


    range = "100...101";
    ledgerRange = strSplit(range,"..");
    listiterator = new listiterator(ledgerRange);
    while(listiterator.more())
    {
        con += listiterator.value();
        listiterator.next();
    }

    startValue  =  conpeek(con,1);
    endValue  =  conPeek(con,4);
    info(EndValue);

}

Find Ledger Account Id by Ledger dimension in AX 2012

To Find Ledger Account Id by Ledger Dimension in Ax 2012

info(strFmt("%1",MainAccount::findByLedgerDimension(3427167077).MainAccountId));


Monday, 5 May 2014

NEN - Financial Dimension Range



 

The task is to set range for finacial dimension .

Issue:
1. Get all the users who are assigned to particular deparment dimension value 
2. To set range for Dimension ( department).
 ========================================================================

Explanation :

1. dimAttributeDep = DimensionAttribute::getAttributeByUnitType(DimensionUnitType::Department);

The above command gets "Department" in to string  "dimAttributeDep"

2. SysQuery::addDimensionAttributeRange(_query,

                                                queryDataSourceStr(PurchTableListPage, PurchaseTable),
                                                fieldId2name(tableNum(PurchTable), fieldnum(PurchTable, DefaultDimension)),
                                                DimensionComponent::DimensionAttribute,
                                                filterDep,
                                                dimAttributeDep.Name);


The above command Sets range for  "Department" in financial Dimension . where filterDep holds the range value ( example 101 - for dimension Department. 


3. departmentRecIds = HcmWorker::getDepartmentRecIds(SysQueryRangeUtil::currentWorkerRecId());
            for (i=1;i<=conLen(departmentRecIds);i++)  // Code for this method is given in below table
            {
                OMOperatingUnit::numberOfWorkers(true, true, conPeek(departmentRecIds,i),DateTimeUtil::utcNow(),setWorkers);
            }
            if (setWorkers.elements() > 0)
            {
                setIterator = new SetIterator(setWorkers);
                setIterator.begin();
                while (setIterator.more())
                {
                   strWorkers += strFmt("%1,",setIterator.value());
}
 


 The above code gets the Workers assigned to particular Department - '101' for department For example. 

================================================================================================================

 



public void initializeQuery(Query _query)

{
worker = HcmWorker::find(SysQueryRangeUtil::currentWorkerRecId());
    if (!worker)
        throw error(strfmt('%1%2', CurUserId(),' has not been linked to any employee record.\nPlease contact you system administrator to rectify the problem.' ));

    filterDep = DirPerson::find(worker.Person).Filter; // filterDep – is assigned value and Range is applied for Department without any check of Filter we applied in front end
    if(filterDep)
    {
        dimAttributeDep = DimensionAttribute::getAttributeByUnitType(DimensionUnitType::Department);

        SysQuery::addDimensionAttributeRange(_query,
                                                queryDataSourceStr(PurchTableListPage, PurchaseTable),
                                                fieldId2name(tableNum(PurchTable), fieldnum(PurchTable, DefaultDimension)),
                                                DimensionComponent::DimensionAttribute,
                                                filterDep,
                                                dimAttributeDep.Name);

}
-----------------------------------------------------------------------------------------------------------------


if (filterCreator == NoYes::Yes)
    {
        if (filterUseHome)
        {
            departmentRecIds = HcmWorker::getDepartmentRecIds(SysQueryRangeUtil::currentWorkerRecId());
            for (i=1;i<=conLen(departmentRecIds);i++)  // Code for this method is given in below table
            {
                OMOperatingUnit::numberOfWorkers(true, true, conPeek(departmentRecIds,i),DateTimeUtil::utcNow(),setWorkers);
            }
            if (setWorkers.elements() > 0)
            {
                setIterator = new SetIterator(setWorkers);
                setIterator.begin();
                while (setIterator.more())
                {
                   strWorkers += strFmt("%1,",setIterator.value());//     Apply range – for Worker Condition – 3 (If it doesn’t get in to this loop , strWorkers = “”) . This is what happening for condition 3 .. it is not moving in to this loop due to data and range .                                                                          value for Worker is “”

                    setIterator.next();
                }
            }
        }
        else
        {
            strWorkers = SysQuery::value(SysQueryRangeUtil::currentWorker());
        }

        rangeWorker.value(strWorkers); //     Apply range – for Worker Condition – 1 ( Current Worker)
                                                   if(filterDep)
        {
            SysQuery::clearDimensionRangesFromQuery(_query);
        }
    }
    Else   // Moves to this code if (filterCreator = NoYes::No)
    {
        rangeWorker.value(SysQuery::valueUnlimited());// Apply range – for Worker Condition – 2 ( All workers)

        if(filterDep)
        {
            SysQuery::addDimensionAttributeRange(_query,
                                                    queryDataSourceStr(PurchTableListPage, PurchaseTable),
                                                    fieldId2name(tableNum(PurchTable), fieldnum(PurchTable, DefaultDimension)),
                                                    DimensionComponent::DimensionAttribute,
                                                    filterDep,
                                                    dimAttributeDep.Name);
        }
    }

  =================================================================================================================


public static container getDepartmentRecIds(HcmWorkerRecId _workerRecId, utcdatetime _asOfDate = DateTimeUtil::utcNow())

{
    #HRMConstants

    HcmPositionWorkerAssignment positionWorkerAssignment;
    HcmPositionDetail           positionDetail;
    HcmPositionDuration         positionDuration;

    ----
    ----
while select ValidTimeState(_asOfDate) Department from positionDetail
            exists join positionWorkerAssignment
            where positionWorkerAssignment.Position == positionDetail.Position &&
                positionWorkerAssignment.Worker == _workerRecId
            exists join positionDuration
                where positionDuration.Position == positionDetail.Position
    {
        result = conIns(result, conLen(result) + 1, positionDetail.Department);
    }
}

Thursday, 23 January 2014

Custom Financial Dimension Update in Sales order


 Created Custom Dimension and need to Update the value based on  some field modification in sales order

public boolean modified()
{
    boolean ret;
   DimensionAttributeValueSetStorage dimstorage;
    Counter i;
    DimensionAttribute modeofdelivery;
    DimensionAttributeValue modeofdeliveryvalue;
    str 255 dimvalue ="10";
    Name dimName="ModeofDelivery";
    ret = super();
    dimstorage = DimensionAttributeValueSetStorage::find(SalesLine.DefaultDimension);
    modeofdelivery = DimensionAttribute::findByName(dimName);
    if(dimvalue)
    {
       modeofdeliveryvalue = DimensionAttributeValue::findByDimensionAttributeAndValue (modeofdelivery,dimvalue,true,true);
        dimstorage.addItem(modeofdeliveryvalue);
    }
    else
        dimstorage.removeDimensionAttribute(DimensionAttribute::findByName(dimName).RecId);

    SalesLine.DefaultDimension = dimstorage.save();

    return ret;
}

Wednesday, 1 January 2014

Links for Financial Dimensions

https://skydrive.live.com/?cid=1613f1612d4c9e73&id=1613F1612D4C9E73%21278&ref=1 - Download imp sessions

http://daxldsoft.blogspot.in/2012/11/ax-2012-financial-dimension-update.html  -> Ax 2012 financial dimension update

Thursday, 19 December 2013

Updating the Customer financial dimension in dynamics ax 2012.

static void setFinancialDimensionToCustomer(CustAccount _custAccount)  
 {  
  CustTable custTable;  
  Struct struct = new Struct();  
  container ledgerDimension;  
  DimensionDefault DimensionDefault;  
  ;  
  struct.add('BookingChannel', '30');  
  struct.add('Carrier', '01');  
  struct.add('Department', '30');  
  struct.add('Destination', '01');  
  struct.add('Division', '30');  
  struct.add('Origin', '01');  
  struct.add('Product', '30');  
  ledgerDimension += struct.fields();  
  ledgerDimension += struct.fieldName(1);  
  ledgerDimension += struct.valueIndex(1);  
  ledgerDimension += struct.fieldName(2);  
  ledgerDimension += struct.valueIndex(2);  
  ledgerDimension += struct.fieldName(3);  
  ledgerDimension += struct.valueIndex(3);  
  ledgerDimension += struct.fieldName(4);  
  ledgerDimension += struct.valueIndex(4);  
  ledgerDimension += struct.fieldName(5);  
  ledgerDimension += struct.valueIndex(5);  
  ledgerDimension += struct.fieldName(6);  
  ledgerDimension += struct.valueIndex(6);  
  ledgerDimension += struct.fieldName(7);  
  ledgerDimension += struct.valueIndex(7);  
  ttsBegin;  
  DimensionDefault = AxdDimensionUtil::getDimensionAttributeValueSetId(ledgerDimension);  
  custTable = CustTable::find(_custAccount, true);  
  custTable.DefaultDimension = DimensionDefault;  
  custTable.update();  
  ttsCommit;  
 }