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

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Pages / Discrepancy when filte...
Power Pages
Answered

Discrepancy when filtering lookup

(1) ShareShare
ReportReport
Posted on by 14

My company are developing a Power Page which will act as an Admissions portal for applicants in an educational context. We have a multistep form and have been following this guide https://www.dancingwithcrm.com/custom-lookup-filtering-powerapps-portal/, to filter some lookups because old entry years / previous programmes should not be an option displayed since are outdated but must remain in the choice since removal would affect historical data.

 

I built the web template, web page, and added custom script to the specific step on the multistep form which appends the options to the drop down for the relevant attributes - drop downs configured with metadata. In the power page front end editor, I can see the returned data is as expected on the page which acts as an endpoint, but when I preview and go to the form page, the options list is empty for the attribute and accessing the endpoint page in the preview demonstrates its returning an empty array/dict. I will add screenshots for context. Once I noticed the discrepancy I tried using postman on the endpoint and similarly the returned data is empty. I don't understand how the front end editor can show the data but elsewhere the endpoint is not working.

kaitlynmockett_1-1719830369753.png

kaitlynmockett_2-1719830409577.png

 

kaitlynmockett_3-1719830480281.png

 

kaitlynmockett_0-1719830349857.png

$(document).ready(function() {
 $.ajax({
 method: "GET",
 url: "/yoe-json-api/",
 cache: false,
 headers: {
 "Content-Type": "application/json"
 }
 })
 .done(function(data) {
 console.log("API response:", data); // Log the data received from the API

 // Clear any existing options
 $("#ans_yearofentry").empty();

 // Check if data.results is an array and has elements
 if (Array.isArray(data.results) && data.results.length > 1) {
 data.results.forEach(element => {
 let option = document.createElement("option");
 option.value = element.yearOfEntry;
 option.innerText = element.yearOfEntry;

 // Append the new option to the select element
 $("#ans_yearofentry").append(option);
 });
 } else {
 console.log("No results found");
 }
 })
 .fail(function(jqXHR, textStatus, errorThrown) {
 console.error("Year of entry API call failed with status: " + textStatus);
 console.error("Error: " + errorThrown);
 });
});

Ultimately, I'd like to know is there a reason for the discrepancy? Also how can I achieve the intended behaviour for the lookups?

 

Any help is much appreciated, thanks, Kaitlyn .

Categories:
I have the same question (0)
  • Ajlan Profile Picture
    237 on at

    Hi @kaitlynmockett ,

    Could you please check if your table has "Read" permissions enabled? Additionally, please debug your code to ensure that your custom page is returning the appropriate records.

     

    Regards

    Ajlan

  • kaitlynmockett Profile Picture
    14 on at

    Hi @Ajlan, I have confirmed the custom page is returning the right records from the editor - the two records are for entry years 2024 & 2025 which is the desired data. The attribute is from the admissions table and this table has Read permissions applied.

  • Ajlan Profile Picture
    237 on at

    @kaitlynmockett 

    Then it seems that the user you are using to access the portal lacks sufficient entity permissions or web roles.

     

    Cheers

  • kaitlynmockett Profile Picture
    14 on at

    I don't believe that is causing the issue. If I apply a global access table permission for the admissions table for all user types - authenticated, admin and anonymous - the issue persists because its returning the same empty data on the custom page which is incorrect. Why would the editor show the correct data but not on the actual site?

  • Fubar Profile Picture
    8,487 Super User 2026 Season 1 on at

    @kaitlynmockett wrote:

    Why would the editor show the correct data but not on the actual site?


    Usually it is the Table permissions as when you are in the editor it does make use of the Web Role permissions, whereas when you are on the Portal it does.  

    After assigning global permission, did you clear the portals cache (e.g. when logged in as a portal user with the Administrator Web Role <your sites url>/_services/about )? (as the SLA to push such updates from Dataverse to the portal is 15 mins)

     

  • kaitlynmockett Profile Picture
    14 on at

    @Fubar, Okay, I did not clear cache, after looking at the site later on I had two entities appear in the dropdown list which do not display the actual string value.

     

    kaitlynmockett_0-1719916526761.png

    However now it is showing all the choices without filtering because the AJAX request is failing for an unknown reason despite no changes to the configuration or script and I am struggling to get these records to display on the dropdown options.

    kaitlynmockett_0-1719918913335.png

     

    Meanwhile the editor shows on the same data in JSON  on the custom page eg. {rooturl}/yoe-json-api/

    kaitlynmockett_2-1719917197283.png

    but not in the site:

    kaitlynmockett_3-1719917304432.png

     

  • Ajlan Profile Picture
    237 on at

    @kaitlynmockett  Here is an alternative way. Hope this help

     

    Step 1: Create a view of "Year of entry" entity and add a filter to display only 2024 and 2025
    View filter.png

     

    Step 2: Go to your form and add the newly created view on to your lookup field as default view and uncheck the "allow user to change view"
    Lookup field.png

    Note: Custom view is the name of my view

     

    Step 3: Go to Power Pages and Configure your table permission for the "Year of entry" entity.

     

    Table permission.png

     

    Step 4: Last step is to Render your lookup as a dropdown

     

    Dropdown.png

     

    Cheers

  • EmadBeshai Profile Picture
    806 Moderator on at

    Hi @kaitlynmockett ,

     

    Please remove the highlighted extra comma

    EmadBeshai_0-1719960162222.png

     

     

    If this post helps you with your problem, please mark this answer as Accepted Solution.

    If you like my response, please give it a Thumbs Up. 

  • Verified answer
    Fubar Profile Picture
    8,487 Super User 2026 Season 1 on at

    The error message you are seeing in the console is indicating your query string or the output is not formatted correctly, it is expecting something to be in "double quotes" so either they are missing or something is terminating a string early.

     

    The numbers being returned are because you appear to be querying a Choice field which is a complex datatype (note: you also need the number as this is what the field needs to be saved with), when you process the output of the FetchXML in the Web Page you are calling (i.e. the page your ajax is calling), you need to extract the label and put it in the JSON being output the label should be accessible by something like {{ item['fieldname'].label }}

     

    Also be aware, whilst it should still work etc the link you provided is the older way of doing the Ajax, the newer way would be to do roughly the same but using the Portals Web API in your main page (at the time that article was written the Portal would not have had the Web API or 'Read' was not exposed in it).

     

  • kaitlynmockett Profile Picture
    14 on at

    Thanks for your replies. They have been most useful. I have managed to achieve the intended filtering for the year of entry field by using {{ item['fieldname'].label }} instead which also fixed the failing AJAX request. I need to create / use apis for more than just this field to filter choices so I will investigate the use of Web API as an alternative method despite the custom page JSON api working. I had not heard or read anything about Web API so appreciate the suggestion.

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!

Congratulations to the March Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Pages

#1
rezarizvii Profile Picture

rezarizvii 61

#2
11manish Profile Picture

11manish 40

#3
oliver.rodrigues Profile Picture

oliver.rodrigues 36 Most Valuable Professional

Last 30 days Overall leaderboard