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

Notifications

Announcements

No record found.

Community site session details

Community site session details

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

I have the same question (0)
  • André Arnaud de Calavon Profile Picture
    301,069 Super User 2025 Season 2 on at

    Hi Srinivas,

    If it is working in a job, but not in your class, you have to verify if the coding is exactly the same or if there are other variables used.

    Also make sure if you are running a class, the incremental CIL has been run.

  • Suggested answer
    Iulian Cordobin Profile Picture
    8,201 on at

    Replace 'select PersonnelNumber from hcmWorker' with 'select * from hcmWorker'.

  • srinivas pamidi Profile Picture
    1,737 on at

    HI Iulian Cordobin,

    still it is not working...

    i don't understand why it is..

    select * from hcmWorker

                       where hcmWorker.PersonnelNumber == worker;

  • Suggested answer
    Iulian Cordobin Profile Picture
    8,201 on at

    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).

  • srinivas pamidi Profile Picture
    1,737 on at

    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?

  • Verified answer
    srinivas pamidi Profile Picture
    1,737 on at

    Now it is working..

    after changing these..

    worker = subStr(dimensionFocus,34,7);

  • Iulian Cordobin Profile Picture
    8,201 on at

    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.

  • André Arnaud de Calavon Profile Picture
    301,069 Super User 2025 Season 2 on at

    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

  • srinivas pamidi Profile Picture
    1,737 on at

    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;

              }

          }

      }

  • Suggested answer
    Community Member Profile Picture
    on at

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

    HcmWorker::findByPersonnelNumber(worker).name;

    If you have Worker RecID , then :

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

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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics AX (Archived)

#1
Martin Dráb Profile Picture

Martin Dráb 4 Most Valuable Professional

#1
Priya_K Profile Picture

Priya_K 4

#3
MyDynamicsNAV Profile Picture

MyDynamicsNAV 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans