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 Apps / Issue with Default Vie...
Power Apps
Unanswered

Issue with Default View Overwritten in Power Platform Form Script

(0) ShareShare
ReportReport
Posted on by 2

I have a script that runs the onLoad event in a form.

This script changes the default view and adds a custom view that is dynamically created based on a fetchxml we are constructing according to some data from the form.

The fetch results are correct, and the view is set correctly if I use the method Xrm.Page.getControl("productid").getDefaultView() after the form has loaded:

Skxtz__0-1702977032591.png

Then i click to see the results of my custom view and:

Skxtz__1-1702977059959.png

 

That's my code script, if you need more details i can publish it all

 

 

 let viewID = "{55ca1807-fb56-4b6f-8e6f-4833d8eea873}";
 formContext.getControl("productid").addCustomView(viewID, "product", "Productos activos por fetch", fetchXml, layout, false);

 formContext.getControl("productid").setDefaultView(viewID);

 

 

 

However, the problem arises when I press "Enter" or "Search" in the field, so that it doesn't show recent values but rather those from the default search. The default search for this field is overwritten before executing my script. Any idea why the default view is being overwritten?

 

 

Thank you very much for your guidance.

I have the same question (0)
  • Parvez Ghumra Profile Picture
    1,579 Moderator on at

    @Skxtz_ If sounds as though some other code, possibly Microsoft code, is overriding your custom behaviour for this lookup. Do you have any other script code (triggered on another event handler), running against this control? Which form is this on?

  • Skxtz_ Profile Picture
    2 on at

    Good Morning,

     

    Thanks for your response, 

     

    We do not have any other script running on this form, and this is the "opportunity line" entity, in the main form in "productid" field.

  • a33ik Profile Picture
    3,306 Most Valuable Professional on at

    I would recommend using addPreSearch to filter the content of your lookups. Works much better - https://learn.microsoft.com/en-us/power-apps/developer/model-driven-apps/clientapi/reference/controls/addpresearch

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 Apps

#1
WarrenBelz Profile Picture

WarrenBelz 542 Most Valuable Professional

#2
Haque Profile Picture

Haque 206

#3
Kalathiya Profile Picture

Kalathiya 201 Super User 2026 Season 1

Last 30 days Overall leaderboard