Skip to main content
Community site session details

Community site session details

Session Id : tXXpVDkkAXu31bpz7z/VEf
Power Pages - Power Apps Portals
Unanswered

How to set lookup field value based on another field value in entity form?

Like (0) ShareShare
ReportReport
Posted on 18 Jun 2021 04:31:39 by 134

Hi everyone,

In the entity form, I have 2 fields. one is License key, data type is "Text".  The other one is prefix number, it's a lookup field.

We have another table called license management as below, which contains license key and prefix number.

 

License management table

License KeyPrefix Number
AAA-AAA-AAA8
BBB-BBB-BBB80

 

I hope that when I input license key in the entity form, Prefix number field will display the corresponding number automatically based on License management table.

Due to our needs, both fields are required and we don't want user to make selection in Prefix number field.

Example:

If we input AAA-AAA-AAA in License key field, Prefix number lookup will only show  the record whose prefix is "8".

 

Any idea about it, pls kindly share with me.

  • OOlashyn Profile Picture
    3,496 Most Valuable Professional on 28 Jun 2021 at 12:07:54
    Re: How to set lookup field value based on another field value in entity form?

    Hi @Audreyma ,

    Please read carefully article that I share before. It shows with an example on how to both call and get an output. On your web template you need to shape return data in a json format, so please do not add any additional html tags. Your output should look something like this:

    {% fetchxml demoData %}
    <fetch version="1.0" output-format="xml-platform" mapping="logical" distinct="false">
     <entity name="cr_autoannounce_prefix">
     <attribute name="cr_licensekey" />
     <attribute name="cr_autoannounce_prefix" />
     <filter type="and">
     <condition attribute="cr_licensekey" operator="not-null" />
     </filter>
     </entity>
    </fetch>
    {% endfetchxml %}
    {
     "totalcount": {{ demoData.results.total_record_count }},
     "morerecords": {{ demoData.results.more_records }},
     "page": {{ demoData.params['page'] | default: 0 }},
     "results": [
     {% for item in demoData.results.entities %}
     {
     "cr_licensekey": "{{ item.cr_licensekey }}",
     "cr_autoannounce_prefix": "{{ item.cr_autoannounce_prefix }}"
     }{% unless forloop.last %},{% endunless %}
     {% endfor -%}
     ]
    }

    You can also pass an entered license key and get a proper prefix so you don't need to query everything. See this article for more details.

  • Audrey Ma Profile Picture
    134 on 24 Jun 2021 at 09:58:47
    Re: How to set lookup field value based on another field value in entity form?

    Hi @OOlashyn 

    Thank you for your sharing.

    I can get the data through the below fetch xml in my test page, but got stuck about how to output corresponding data in another web page through Javascript.

    {% fetchxml demoData %}
    <fetch version="1.0" output-format="xml-platform" mapping="logical" distinct="false">
     <entity name="cr_autoannounce_prefix">
     <attribute name="cr_licensekey" />
     <attribute name="cr_autoannounce_prefix" />
     <filter type="and">
     <condition attribute="cr_licensekey" operator="not-null" />
     </filter>
     </entity>
    </fetch>
    {% endfetchxml %}
    
    <b>Total Records:</b> {{demoData.results.entities.size}}</br>
    {% for result in demoData.results.entities %}
    License key: {{result.cr_licensekey}}</br>
    Prefix number: {{result.cr_autoannounce_prefix}}</br>
    {% endfor %}

     Fetch xml output in my test page:

    Audreyma_0-1624528166424.png

    I hope that if I input AAAA-AAAA-AAAA in license key field, prefix number will show 80.

    Could you give me some more instructions about Javascript?(sorry for my poor knowleage about code writing)

  • OOlashyn Profile Picture
    3,496 Most Valuable Professional on 21 Jun 2021 at 12:39:46
    Re: How to set lookup field value based on another field value in entity form?

    Hi @Audreyma ,

    What you can do is when user enters the license key query data from the system and based on the response populate the field. Unfortunately, portal Web API doesn't support read operations (at least yet), so you will need to use Web Page as an API approach. Basically, you create a web template with fetchxml query to which you can pass different parameters via url query string and create a web page based on that template. Then you can just call that page via javascript. You can find more about this approach here - https://colinvermander.wordpress.com/2017/04/17/dynamics-365-portals-use-liquid-to-return-json-or-xml/

  • Audrey Ma Profile Picture
    134 on 21 Jun 2021 at 07:29:34
    Re: How to set lookup field value based on another field value in entity form?

    Any ideas about this issue? 

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 2 Super Users!

A new season of Super Users has arrived, and we are so grateful for…

Paul Stork – Community Spotlight

We are honored to recognize Paul Stork as our July 2025 Community…

Congratulations to the June Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Pages

#1
Lucas001 Profile Picture

Lucas001 60 Super User 2025 Season 2

#2
Fubar Profile Picture

Fubar 55 Super User 2025 Season 2

#3
surya narayanan Profile Picture

surya narayanan 35

Loading complete