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

Notifications

Announcements

Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Apps / how to copy data from ...
Power Apps
Unanswered

how to copy data from one table to another when selecting a lookup field in model driven app

(0) ShareShare
ReportReport
Posted on by 52

Hello everyone

 

I am trying to get the data of a related record that i select in a lookup. So when the lookup field is selected, that the entire form gets filled up with the data that comes from that related record in the lookup field. Can anyone help me to fix

I have the same question (0)
  • Verified answer
    ChrisPiasecki Profile Picture
    6,422 Most Valuable Professional on at

    Hi @jorenchristiaen,

     

    Do you need to save the same data from the related record, or do you just need to view the related data? If you just need to view related data, you could create a Quick View form for the related table and add it to your form. The quick view form would show up whenever the Lookup has a selected record populated.

     

    If you need to populate data from a related entity, you can define Attribute Mappings on the 1:N relationship. If on the related record form you have a subgrid to this entity and click + (Add New), when it opens the create new form it will pre-populate the values of the related record including the lookup. Note that this will not auto-populate if you are just creating a new record without coming from the related record.

     

    The other way to populate the fields is with a JavaScript web resource, registered to the OnChange event of the Lookup field. You would retrieve the related record using the Lookup value selected. Then you can set the form values using the related record you retrieved. 

     

    ---
    Please click Accept as Solution if my post answered your question. This will help others find solutions to similar questions. If you like my post and/or find it helpful, please consider giving it a Thumbs Up.

     

  • nandiishdave5 Profile Picture
    8 on at

    Thanks for the question and answer both. It helped me to solve my problem. 

     

    For second solution that you have given I have written simple js code and put it to field OnChange Event. 

     

    function OnChangeEvent(executionContext, lookupfield, namefield) {
      var formContext = executionContext.getFormContext();
      if (formContext.getAttribute(lookupfield).getValue() != null) {
        formContext
          .getAttribute(namefield)
          .setValue(formContext.getAttribute(lookupfield).getValue()[0].name);
      } else {
        formContext.getAttribute(namefield).setValue("");
      }
    }
     
    Please refer it if anyone needs help 🙂
  • nandiishdave5 Profile Picture
    8 on at

    Thanks for the question. It wanted to do same thing. 

     

    For second solution that you have given I have written simple js code and put it to field OnChange Event. 

     

    function OnChangeEvent(executionContextlookupfieldnamefield) {
      var formContext = executionContext.getFormContext();
      if (formContext.getAttribute(lookupfield).getValue() != null) {
        formContext
          .getAttribute(namefield)
          .setValue(formContext.getAttribute(lookupfield).getValue()[0].name);
      } else {
        formContext.getAttribute(namefield).setValue("");
      }
    }
    Hopefully it will help to someone who needs similar solution 🙂
    Please refer it if anyone needs help 

     

  • danny90 Profile Picture
    149 on at

    Hi @nandiishdave5 

     

    Any chance you could elaborate on how to use this Js? im really struggling to get it to work 🙂

     

    Thanks!

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

Forum hierarchy changes are complete!

In our never-ending quest to improve we are simplifying the forum hierarchy…

Ajay Kumar Gannamaneni – Community Spotlight

We are honored to recognize Ajay Kumar Gannamaneni as our Community Spotlight for December…

Leaderboard > Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 717 Most Valuable Professional

#2
Michael E. Gernaey Profile Picture

Michael E. Gernaey 329 Super User 2025 Season 2

#3
Power Platform 1919 Profile Picture

Power Platform 1919 268

Last 30 days Overall leaderboard