cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Audreyma
Helper III
Helper III

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

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.

4 REPLIES 4
Audreyma
Helper III
Helper III

Any ideas about this issue? 

OOlashyn
Super User
Super User

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

----------------------------------------------------
If you find this post helpful consider marking it as a solution to help others find it.

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)

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.

----------------------------------------------------
If you find this post helpful consider marking it as a solution to help others find it.

Helpful resources

Announcements
PA User Group

Welcome to the User Group Public Preview

Check out new user group experience and if you are a leader please create your group

Power Query PA Forum 768x460.png

Check it out!

Did you know that you can visit the Power Query Forum in Power BI and now Power Apps

V3_PVA CAmpaign Carousel.png

Community Challenge - Giveaways!

Participate in the Power Virtual Agents Community Challenge

Carousel 2021 Release Wave 2 Plan 768x460.jpg

2021 Release Wave 2 Plan

Power Platform release plan for the 2021 release wave 2 describes all new features releasing from October 2021 through March 2022.

Carousel April Dunnam Updated 768x460.jpg

Urdu Hindi D365 Bootcamp

Dont miss our very own April Dunnam’s The Developer Guide to the Galaxy! Find out what the Power Platform has to offer for the traditional developer.

Users online (1,894)