D365FFO – AX – Modify/update the Default dimensions through X++

HcmWorker hcmWorker;
HcmEmployment hcmEmployment,hcmEmploymentup;
DimensionAttributeValueSetStorage dimStorage = new DimensionAttributeValueSetStorage();
DimensionAttribute dimAttrC,dimAtrrCC;
DimensionAttributeValue dimAttrCValue,dimAtrrCCValue;
DimensionDefault defaultDimension;

int i;
str costcenter1,costcenter2, name1,name2;

dimStorage = DimensionAttributeValueSetStorage::find(this.NewDefaultDimension);

for (i=1 ; i<= dimStorage.elements() ; i++)
{
if(i==1)
{
name1 = DimensionAttribute::find(dimStorage.getAttributeByIndex(i)).Name; // cost center
costcenter1 = dimStorage.getDisplayValueByIndex(i);
}
else
{
name2 = DimensionAttribute::find(dimStorage.getAttributeByIndex(i)).Name; // class
costcenter2 = dimStorage.getDisplayValueByIndex(i);
}
}

select firstonly hcmWorker where hcmWorker.PersonnelNumber == this.PersonnelNumber;
select firstonly hcmEmployment where hcmEmployment.Worker == hcmWorker.RecId;

defaultDimension = hcmEmployment.DefaultDimension;
dimStorage = DimensionAttributeValueSetStorage::find(defaultDimension);

dimAttrC = DimensionAttribute::findByName(name2);
dimAtrrCC = DimensionAttribute::findByName(name1);

dimAttrCValue = DimensionAttributeValue::findByDimensionAttributeAndValue(dimAttrC,costcenter2 , false, true);
dimAtrrCCValue = DimensionAttributeValue::findByDimensionAttributeAndValue(dimAtrrCC,costcenter1 , false, true);

dimStorage.addItem(dimAttrCValue);
dimStorage.addItem(dimAtrrCCValue);
select forupdate hcmEmploymentup where hcmEmploymentup.worker == hcmWorker.RecId;
if(hcmEmploymentup)
{
ttsbegin;
hcmEmploymentup.defaultDimension = dimStorage.save();
hcmEmploymentup.validTimeStateUpdateMode(ValidTimeStateUpdate::Correction);
hcmEmploymentup.ValidFrom = DateTimeUtil::getSystemDateTime();
hcmEmploymentup.ValidTo =DateTimeUtil::maxValue();
hcmEmploymentup.update();
ttscommit;
}

Rispondi

Inserisci i tuoi dati qui sotto o clicca su un'icona per effettuare l'accesso:

Logo di WordPress.com

Stai commentando usando il tuo account WordPress.com. Chiudi sessione /  Modifica )

Google photo

Stai commentando usando il tuo account Google. Chiudi sessione /  Modifica )

Foto Twitter

Stai commentando usando il tuo account Twitter. Chiudi sessione /  Modifica )

Foto di Facebook

Stai commentando usando il tuo account Facebook. Chiudi sessione /  Modifica )

Connessione a %s...