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

Announcements

Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Pages / How to set lookup fiel...
Power Pages
Unanswered

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

(0) ShareShare
ReportReport
Posted on 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.

Categories:
I have the same question (0)
  • Audrey Ma Profile Picture
    134 on at

    Any ideas about this issue? 

  • OOlashyn Profile Picture
    3,496 Most Valuable Professional on at

    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 at

    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 at

    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.

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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Users!

Kudos to our 2025 Community Spotlight Honorees

Congratulations to our 2025 community superstars!

Leaderboard > Power Pages

#1
Suriyanarayanan V Profile Picture

Suriyanarayanan V 41

#2
oliver.rodrigues Profile Picture

oliver.rodrigues 28 Most Valuable Professional

#3
Fubar Profile Picture

Fubar 16 Super User 2026 Season 1

Last 30 days Overall leaderboard