I would like to ask this, how i can filter or find the current worker financial dimension on employment history, in X++. i have this code which display all the Personnel Number and Business Unit of the workers.
public static void main(Args _args)
{
HcmEmployment hcmEmployment;
DimensionAttributeValueSetItem setItem;
DimensionAttributeValue dimAttrValue;
DimensionAttribute dimAttribute;
;
dimAttribute = DimensionAttribute::findByName('BusinessUnit');
anytype hcm = HcmWorker::find(HcmWorkerLookup::currentWorker()).PersonnelNumber;
ttsbegin;
select hcmEmployment
join RecId, DisplayValue from setItem where setItem.DimensionAttributeValueSet == hcmEmployment.DefaultDimension join dimAttrValue
where dimAttrValue.RecId == setItem.DimensionAttributeValue && dimAttrValue.DimensionAttribute == dimAttribute.RecId && dimAttrValue.IsDeleted == false;
info(strFmt("Employee = %1 %2 = %3 ",HcmWorker::find(hcmEmployment.Worker).PersonnelNumber, dimAttribute.Name, setItem.DisplayValue));
ttscommit;
}
Please Help me.
Thank you sir. i got it already thank you, this is a huge help for us. thank you
Also, no need of ttsbegin and ttscommit on your code. You are just trying to fetch info from database not going to perform update operation.
Thanks,
Girish S.
You can just add where condition in HcmEmployment table and map the worker field to HcmWorkerLookup::CurrentWorker.
Refer to the below code.
public static void main(Args _args) { HcmEmployment hcmEmployment; DimensionAttributeValueSetItem setItem; DimensionAttributeValue dimAttrValue; DimensionAttribute dimAttribute; ; dimAttribute = DimensionAttribute::findByName('BusinessUnit'); anytype hcm = HcmWorker::find(HcmWorkerLookup::currentWorker()).PersonnelNumber; select firstonly * from hcmEmployment where hcmEmployment.Worker == HcmWorkerLookup::currentWorker() join RecId, DisplayValue from setItem where setItem.DimensionAttributeValueSet == hcmEmployment.DefaultDimension join dimAttrValue where dimAttrValue.RecId == setItem.DimensionAttributeValue && dimAttrValue.DimensionAttribute == dimAttribute.RecId && dimAttrValue.IsDeleted == false; info(strFmt("Employee = %1 %2 = %3 ",HcmWorker::find(hcmEmployment.Worker).PersonnelNumber, dimAttribute.Name, setItem.DisplayValue)); }
Thanks,
Girish S.
can you gave me a rewrite code?
You can make use of HcmWorkerLookup::CurrentWorker - This will return current worker recid - This RecId you can map with HcmEmployment Table.
Thanks,
Girish S.
That code display all the workers personnel number and dimension value, the problem is how i can code to display only the current user default dimension.
Hi,
You can make use of DefaultDimensionView to get the default dimension of the worker like Business Unit, Cost center etc.
You can relateHcmWorker - HcmEmployment and DefaultDimensionView using "DefaultDimension" field.
Field "Name" in "DefaultDimensionView" will store Business Unit, Department etc.
Thanks,
Girish S.
Your code is difficult to read, because you pasted it in a wrong way and therefore it lost line indentation. Please always use Insert > Code (in the rich-formatting view). Let me do it for you this time, and improve it a bit:
HcmEmployment hcmEmployment; DimensionAttributeValueSetItem setItem; DimensionAttributeValue dimAttrValue; DimensionAttribute dimAttribute = DimensionAttribute::findByName('BusinessUnit'); select Worker from hcmEmployment join DisplayValue from setItem where setItem.DimensionAttributeValueSet == hcmEmployment.DefaultDimension exists join dimAttrValue where dimAttrValue.RecId == setItem.DimensionAttributeValue && dimAttrValue.DimensionAttribute == dimAttribute.RecId && dimAttrValue.IsDeleted == false; info(strFmt("Employee = %1 %2 = %3", HcmWorker::find(hcmEmployment.Worker).PersonnelNumber, dimAttribute.Name, setItem.DisplayValue));
Now, what problem do you have with it?
André Arnaud de Cal...
291,969
Super User 2025 Season 1
Martin Dráb
230,842
Most Valuable Professional
nmaenpaa
101,156