How to update worker financial dimension in Dynamics AX 2012 Through X++

How to update worker financial dimension in Dynamics AX 2012 Through X++

static void updateWorkerFinancialDimension(Args _args)
{
 
    DimensionAttributeValueSetStorage   dimStorage;
    DimensionAttribute                  dimAttribute;
    DimensionAttributeValue             dimAttributeValue;
    HcmWorker                           hcmWorker;
    HcmEmployment                       hcmEmployment;




    hcmWorker           = HcmWorker::findByPersonnelNumber('10001');
    dimAttribute        = DimensionAttribute::findByName("Dimension name");
     
    hcmEmployment.validTimeStateUpdateMode(ValidTimeStateUpdate::Correction);
    while select forUpdate hcmEmployment
            where hcmEmployment.LegalEntity == CompanyInfo::find().RecId
                && hcmEmployment.Worker       == hcmWorker.RecId
               
    {
            ttsBegin;

            dimStorage          = DimensionAttributeValueSetStorage::find(hcmEmployment.DefaultDimension);
            dimAttributeValue   = DimensionAttributeValue::findByDimensionAttributeAndValue(dimAttribute, 'Dimension value' ,true, true);

            dimStorage.addItem(dimAttributeValue);
            hcmEmployment.DefaultDimension = dimStorage.save();
            hcmEmployment.doUpdate();
            ttsCommit;
    }

}

Comments

Popular posts from this blog

How to loop through enum in dynamics ax 2012 using x++

How to read from csv file in Dynamics AX 2012 Through X++

How to Create Transfer Journal in Dynamics AX 2012 Through X++