Skip to main content

Notifications

Microsoft Dynamics AX (Archived)

How to get the Worker Name from Worker.

(0) ShareShare
ReportReport
Posted on by 1,737

I am Writing the Code in DP Class to split the Ledger account and display individually..

But i am Unable to get the Worker name 

dimensionFocus  = 14240301-00000002-00000021-100020;

worker = subStr(dimensionFocus,33,7);
select PersonnelNumber from hcmWorker
where hcmWorker.PersonnelNumber == worker;
workerName = hcmWorker.name();

In this Worker is Showing, i am not getting worker name.

I am Writing this code in Job it is working, in class it is Not Working...

*This post is locked for comments

  • André Arnaud de Calavon Profile Picture
    André Arnaud de Cal... 292,031 Super User 2025 Season 1 on at
    RE: How to get the Worker Name from Worker.

    Hi Srinivas,

    I'm losing you now. You didn't mention 'budgettmpbalance' before in your question. Is this related to this question? tmp means temporary, so there isn't a related, I guess. How the temporary table is built up, depends on settings and usage of the AX environment. So this also determines if in some point of time the values in the budgettmpbalance and generaljournalaccountentry are the same or not.

  • srinivas pamidi Profile Picture
    srinivas pamidi 1,737 on at
    RE: How to get the Worker Name from Worker.

    Yes I am Totally agree with you..

    but why this budgettmpbalance.dimensionfocus is not equal to the generaljournalaccountentry.ledgeraccount

    how to find out a realtion?

    how to get the ledgerdimension based on the Budgettmpbalance.dimensionfocus in RDP class?

  • André Arnaud de Calavon Profile Picture
    André Arnaud de Cal... 292,031 Super User 2025 Season 1 on at
    RE: How to get the Worker Name from Worker.

    Hi Srinivas,

    You are using the LedgerAccount field which indeed is a string field. Note that within a legal entity different accounts can have another number of dimensions or no dimension. Also the order can be different.

    The field LedgerDimension is having a record ID reference which can be used in the coding example provided in the blog.

  • Suggested answer
    Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: How to get the Worker Name from Worker.

    If you have Worker ID (Personnel Number), then :

    HcmWorker::findByPersonnelNumber(worker).name;

    If you have Worker RecID , then :

    HcmWorker::find(workerRecid).name();

  • srinivas pamidi Profile Picture
    srinivas pamidi 1,737 on at
    RE: How to get the Worker Name from Worker.

    Hi Andre,

    First i am try this above scenario, but i am unable to pass the Current dimension focus in to general journal account entry table Ledger account..

    That's why i am choose this way..

    Please check my code..

    In this i am unable to find out a realtion for generaljournalAccountEntry and dimension focus of the budget tmp balance table

    select generalJournalAccountEntry

      where generalJournalAccountEntry.LedgerAccount == this.DimensionFocus;//"2221100-00000021-00000101-00000027";

      //Fetch the Value combination record

      dimensionAttributeValueCombination = DimensionAttributeValueCombination::find(generalJournalAccountEntry.LedgerDimension);

      // Get dimension storage

      dimensionStorage = DimensionStorage::findById(generalJournalAccountEntry.LedgerDimension);

      if (dimensionStorage == null)

      {

          throw error("@SYS83964");

      }

      // Get hierarchy count

      hierarchyCount = dimensionStorage.hierarchyCount();

      //Loop through hierarchies to get individual segments

      for(hierarchyIndex = 1; hierarchyIndex <= hierarchyCount; hierarchyIndex++)

      {

          //Get segment count for hierarchy

          segmentCount = dimensionStorage.segmentCountForHierarchy(hierarchyIndex);

          //Loop through segments and display required values

          for (segmentIndex = 1; segmentIndex <= segmentCount; segmentIndex++)

          {

              // Get segment

              segment = dimensionStorage.getSegmentForHierarchy(hierarchyIndex, segmentIndex);

              // Get the segment information

              if (segment.parmDimensionAttributeValueId() != 0)

              {

                  // Get segment name

                  segmentName = DimensionAttribute::find(DimensionAttributeValue::find(segment.parmDimensionAttributeValueId()).DimensionAttribute).Name;

                  //Get segment value (id of the dimension)

                  segmentValue        = segment.parmDisplayValue();

                  //Get segment value name (Description for dimension)

                  if(segmentName == 'MainAccount')

                  {

                  MainAccountDescription  = segment.getName();

                  }

                  if(segmentName == 'BusinessUnit')

                  {

                  BusinessUnitDescription  = segment.getName();

                  }

                  if(segmentName == 'Zone')

                  {

                  ZoneDescription  = segment.getName();

                  }

                  if(segmentName == 'Department')

                  {

                  DepartmentDescription  = segment.getName();

                  }

                  this.SG_Name = MainAccountDescription + ' -' + BusinessUnitDescription + ' -' + ZoneDescription + ' -' + DepartmentDescription;

              }

          }

      }

  • André Arnaud de Calavon Profile Picture
    André Arnaud de Cal... 292,031 Super User 2025 Season 1 on at
    RE: How to get the Worker Name from Worker.

    Hi Srinivas,

    It would be more safe to use the DimensionStorage and DimensionStorageSegment classes to retrieve the personnel number. If the length of one of the dimensions will be different in another environment it isn't working with the hardcoded subStr command. Have a look at the next blog how to use this: sumitsaxfactor.wordpress.com/.../getting-individual-dimension-combination-valuesdimension-storage-class-ax-2012

  • Iulian Cordobin Profile Picture
    Iulian Cordobin 8,201 on at
    RE: How to get the Worker Name from Worker.

    Please note that the replacement of the select field list is also an important change, since you are using in the name method other fields from the buffer and you need to load them.

  • Verified answer
    srinivas pamidi Profile Picture
    srinivas pamidi 1,737 on at
    RE: How to get the Worker Name from Worker.

    Now it is working..

    after changing these..

    worker = subStr(dimensionFocus,34,7);

  • srinivas pamidi Profile Picture
    srinivas pamidi 1,737 on at
    RE: How to get the Worker Name from Worker.

    HI Iulian Cordobin,

    I am Removing the Caches and Remove the Usage, still it is not working..

    is there is any other way to get the worker name from worker id?

  • Suggested answer
    Iulian Cordobin Profile Picture
    Iulian Cordobin 8,201 on at
    RE: How to get the Worker Name from Worker.

    I assume you made the code change. After this, since it is a DP class, perform a full refresh of the caches (from the Development workspace -> Tools -> Caches / all 4 entries).

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…

Vahid Ghafarpour – Community Spotlight

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

Congratulations to the January Top 10 leaders!

Check out the January community rock stars...

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 292,031 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 230,868 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans