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 / dynamically change vie...
Power Apps
Unanswered

dynamically change view on polymorphic form field

(0) ShareShare
ReportReport
Posted on by 167

In my model-driven app, I have a polymorphic field, Resource that refers to 2 entity types-- Facility and LabourRate. On my form, I've set the Resource field to refer to a view from Facility and a view from LabourRate. Under some conditions, I need the Resource lookup to only show Facilities or only show LabourRates.

 

I think this should be possible by using javascript to temporarily change the lookup views that the Resource field refers to. But I'm not clear on the document model so I don't know how to best approach this.

 

Any hints or good info sources?

I have the same question (0)
  • Devikumari Krishna Profile Picture
    988 Super User 2024 Season 1 on at

    Hi @JenniferK ,

    Please find the link below which is very useful for multi table lookups (polymorphic field)

    Multi-Table Lookup/Polymorphic Lookup Field in Dynamics 365 CE – Dynamics 365 CE and Power Platform (wordpress.com)

    -------------------------------------------------------------------------
    If I have answered your question, please mark your post as Solved.
    If you like my response, please give it a Thumbs Up.

    My Blog: Dynamics 365 Key Topics – https://d365topicsbydk.com/
    My Youtube Channel : https://www.youtube.com/channel/UCxSIryP2ah2VpEFr-Z72t1A

     

    Regards

    Devi

  • Bipin D365 Profile Picture
    971 on at

    Hi,

     

    Use below javascript code to achieve your requirement.

    function onLoad(executionContext){
    	formContext = executionContext.getFormContext();
    	var isFTE=formContext.getControl("msft_isfulltimeemployee").getValue();
    	alert("Full Time Employee"+isFTE);
    	if(isFTE=="Yes")
    	{
    		alert(1);
    	formContext.getControl("new_polymorphicfieldid").setEntityTypes(['bc_visit']);
    	}
    	else
    	{
    		alert(2);
    	formContext.getControl("new_polymorphicfieldid").setEntityTypes(['bc_building']);
    	}
    }

     

    I have created the polymorphic lookup field pointing to Visit and Building entity.

     

    bipinshan_0-1639550519418.png

     

    Add this code  onload and onchange of field event.

     

    Please mark my answer verified if this is helpful!

    Regards,

    Bipin Kumar

    Follow my Blog: https://xrmdynamicscrm.wordpress.com/

     

  • Ram Prakash Duraisamy Profile Picture
    5,732 Super User 2026 Season 1 on at

    Hello @JenniferK,

     

    You can try below code

     

    1. Navigate to https://make.powerapps.com

    2. Click Dataverse

    3. Expand Table where Polymorphic field available

    4. Click Forms

    5. Open Main Form then Click Events --> Click Add Library --> Click Create New Webresouce --> name it and select type as Javascript and write below code

     

    function SetDefaultView(executionContext) {
    var formContext = executionContext.getFormContext();
    if(formContext.getAttribute("FIELDTOVERIFY").getValue()===true){
    var customerControl = Xrm.Page.getControl("FILEDLOGICLNAME");
    if (customerControl.getEntityTypes().length > 1) {
    customerControl.setEntityTypes(['Facilities']);
    }
    else{
    var customerControl = Xrm.Page.getControl("FILEDLOGICLNAME");
    if (customerControl.getEntityTypes().length > 1) {
    customerControl.setEntityTypes(['LabourRates']);
    }
    }}

     

    Click Ok and in the ONLOAD operation call the funciton SetDefaultView

     

    Thats it 🙂 

     

    Save Publish and Refresh the Form to cross check

     

    Please mark as Answer if it is helpful and provide Kudos


    Subscribe : https://www.youtube.com/channel/UCnGNN3hdlKBOr6PXotskNLA
    Blog : https://microsoftcrmtechie.blogspot.com

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 Apps

#1
11manish Profile Picture

11manish 600

#2
WarrenBelz Profile Picture

WarrenBelz 478 Most Valuable Professional

#3
Valantis Profile Picture

Valantis 322

Last 30 days Overall leaderboard