Skip to main content

Notifications

Announcements

No record found.

Finance | Project Operations, Human Resources, ...
Suggested answer

Auto populate the fields values

Posted on by 36
Hi All,
 
I have created a form having fields Person(lookup field-through relation with hcmworker),location,jobposition and Name...When i select a person from lookup then the other 3 fields will show the information related to that selected person.
 
Kindly suggest me a solution for this ...how we will achieve this..
Thanks in advance
 
 
Thanks,
Prasad N.
  • André Arnaud de Calavon Profile Picture
    André Arnaud de Cal... 291,280 Super User 2024 Season 2 on at
    Auto populate the fields values
    Hi Prasad,
     
    In case the worker name will be filled and not the location, then the worker might not have an office location defined or not correctly. Have you verified the worker settings? You can also check the contents of the method HCMWorker::OfficeLocation() and see how the value is being retrieved.  
  • PN-21051232-0 Profile Picture
    PN-21051232-0 36 on at
    Auto populate the fields values
    Hi Andre,
     
    out of 3 fields 2 fields getting data when i select a person from lookup...but location is not getting data...why because this will get from DimFinancialTag table Value field data to reflect in the location field...can you please guide me how we will get this through the indirect relation between HcmWorker and Dimfinancialtag..
     
    Thanks,
    Prasad.
  • André Arnaud de Calavon Profile Picture
    André Arnaud de Cal... 291,280 Super User 2024 Season 2 on at
    Auto populate the fields values
    Hi Prasad,
     
    Have you already tried your new coding and what is the outcome? I don't know the details of your EH_ITAppAccess table, but it doesn't make sense to use the record ID of this table to find the worker. You would need to use this.Person instead of this.RecId.
     
    If you are using workerTable.primaryPositionId(), you don't need to find the HCMPosition anymore. You are still trying to find a record with the wrong field. Then the if statement will return false and the primary position ID will no be filled.
  • PN-21051232-0 Profile Picture
    PN-21051232-0 36 on at
    Auto populate the fields values
    Hi Andre,
     
    Below is the code i used in my table level...can you please check and do the corrections if any...please
     
     public void modifiedField(FieldId _fieldId)
        {
            super(_fieldId);
            HcmWorker                   workerTable;
            HcmPosition                 hcmPosition;
           
            if (_fieldId == fieldNum(EH_ITAppAccess, Person))
            {
                if (this.Person)
                {
                    // Retrieve HcmWorker record once
                    workerTable = HCMWorker::findByPerson(this.RecId);
                    // Check if HcmWorker record exists
                    if (workerTable)
                    {
                        this.WorkerName = workerTable.searchName();
                        // Retrieve office location only if HcmWorker record exists
                        this.Location = workerTable.officeLocation();
                    }
                    // Retrieve HcmPosition record once
                    hcmPosition = HcmPosition::findByPosition(this.Person);
                    // Check if HcmPosition record exists
                    if (hcmPosition)
                    {
                        // Retrieve job position only if HcmPosition record exists
                        this.JobPosition = workerTable.primaryPositionId();
                    }
                }
            }
        }
  • Suggested answer
    André Arnaud de Calavon Profile Picture
    André Arnaud de Cal... 291,280 Super User 2024 Season 2 on at
    Auto populate the fields values
    Hi Prasad,
     
    You have some issues in your coding, I think. What value is stored in the Person field? If it is the DirParty reference, you won't find any record if you use the mehtod HCMWorker::findByPersonnelNumber. This method expects a Personnel number. Probably you need to use HCMWorker::findByPerson instead.
    The same is also an issue with finding a position. The method you used expects a position value, not a person. There is a method on the HCMWorker table to find the primary position of the worker.
     
     
  • PN-21051232-0 Profile Picture
    PN-21051232-0 36 on at
    Auto populate the fields values
    Hi Andre,
     
    i tried the code similar like below ....
    Please check...please reply with corrected code (if any)
     
    public void modifiedField(FieldId _fieldId)
    {
        HcmWorker                   workerTable;
        HcmPosition                 hcmPosition;
        super(_fieldId);
        if (_fieldId == fieldNum(EH_ITAppAccess, Person))
        {
            if (this.Person)
            {
                // Retrieve HcmWorker record once
                workerTable = HcmWorker::findByPersonnelNumber(this.Person);
                // Check if HcmWorker record exists
                if (workerTable)
                {
                    this.WorkerName = workerTable.searchName();
                    // Retrieve office location only if HcmWorker record exists
                    this.Location = workerTable.officeLocation();
                }
                // Retrieve HcmPosition record once
                hcmPosition = HcmPosition::findByPosition(this.Person);
                // Check if HcmPosition record exists
                if (hcmPosition)
                {
                    // Retrieve job position only if HcmPosition record exists
                    this.JobPosition = hcmPosition.description();
                }
            }
        }
    }

     
  • André Arnaud de Calavon Profile Picture
    André Arnaud de Cal... 291,280 Super User 2024 Season 2 on at
    Auto populate the fields values
    Hi Prasad,
     
    Can you share the coding you used in your current attempt?
  • PN-21051232-0 Profile Picture
    PN-21051232-0 36 on at
    Auto populate the fields values
    Hi Andre,
     
    Thanks for the reply...
     
    Here, the other 3 fields are display fields in HcmWorker table ..i tried to call these methods in table level but data not populating in the respected fields..
     
    can you please explain more elaborate....please
     
     
    Thanks ,
    prasad N. 
  • André Arnaud de Calavon Profile Picture
    André Arnaud de Cal... 291,280 Super User 2024 Season 2 on at
    Auto populate the fields values
    HI Prasad,
     
    You can take two approaches here. You can have physical fields for the other 3 fields or use display methods. In case of physical fields, you can add logic to the table method modifiedField() and fill them. With virtual fields, the data will be always show current values and prevent data redundancy or the need to update values in case the master data changes. 
  • PN-21051232-0 Profile Picture
    PN-21051232-0 36 on at
    Auto populate the fields values
    Hi Kevin,
     
    Thanks for the reply...
     
    can you please tell me on which method and where(form/table) we need to do the field customization ...please send/post the code,if you dont mind...i tried with modified field method in form as well as table, but it is not working.
     
     
    Thanks,
    Prasad N.

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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,280 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,235 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Product updates

Dynamics 365 release plans