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;
}
}
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
Post a Comment