web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
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.

I have the same question (0)
  • Martin Dráb Profile Picture
    238,780 Most Valuable Professional on at

    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?

  • Verified answer
    GirishS Profile Picture
    27,833 Moderator on at

    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.

  • Suggested answer
    Coders Profile Picture
    20 on at

    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.

  • Suggested answer
    GirishS Profile Picture
    27,833 Moderator on at

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

    Thanks,

    Girish S.

  • Coders Profile Picture
    20 on at

    can you gave me a rewrite code?

  • Verified answer
    GirishS Profile Picture
    27,833 Moderator on at

    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.

  • GirishS Profile Picture
    27,833 Moderator on at

    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.

  • Coders Profile Picture
    20 on at

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

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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Congratulations to our 2025 Community Spotlights

Thanks to all of our 2025 Community Spotlight stars!

Leaderboard > Finance | Project Operations, Human Resources, AX, GP, SL

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 514 Super User 2026 Season 1

#2
Giorgio Bonacorsi Profile Picture

Giorgio Bonacorsi 390

#3
Adis Profile Picture

Adis 266 Super User 2026 Season 1

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans