Skip to main content

Notifications

Finance | Project Operations, Human Resources, ...
Answered

Find the Current worker Default Dimension

(0) ShareShare
ReportReport
Posted on by 20

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.

  • Coders Profile Picture
    Coders 20 on at
    RE: Find the Current worker Default Dimension

    Thank you sir. i got it already thank you, this is a huge help for us. thank you

  • GirishS Profile Picture
    GirishS 27,821 Super User 2024 Season 1 on at
    RE: Find the Current worker Default Dimension

    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.

  • Verified answer
    GirishS Profile Picture
    GirishS 27,821 Super User 2024 Season 1 on at
    RE: Find the Current worker Default Dimension

    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.

  • Coders Profile Picture
    Coders 20 on at
    RE: Find the Current worker Default Dimension

    can you gave me a rewrite code?

  • Suggested answer
    GirishS Profile Picture
    GirishS 27,821 Super User 2024 Season 1 on at
    RE: Find the Current worker Default Dimension

    You can make use of HcmWorkerLookup::CurrentWorker - This will return current worker recid - This RecId you can map with HcmEmployment Table.

    Thanks,

    Girish S.

  • Suggested answer
    Coders Profile Picture
    Coders 20 on at
    RE: Find the Current worker Default Dimension

    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.

  • Verified answer
    GirishS Profile Picture
    GirishS 27,821 Super User 2024 Season 1 on at
    RE: Find the Current worker 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.

  • Martin Dráb Profile Picture
    Martin Dráb 230,842 Most Valuable Professional on at
    RE: Find the Current worker Default Dimension

    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?

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Announcing Forum Attachment Improvements!

We're excited to announce that attachments for replies in forums and improved…

Vahid Ghafarpour – Community Spotlight

We are excited to recognize Vahid Ghafarpour as our February 2025 Community…

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,969 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 230,842 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Product updates

Dynamics 365 release plans