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

Notifications

Announcements

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,593 Super User 2025 Season 2 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

Forum hierarchy changes are complete!

In our never-ending quest to improve we are simplifying the forum hierarchy…

Ajay Kumar Gannamaneni – Community Spotlight

We are honored to recognize Ajay Kumar Gannamaneni as our Community Spotlight for December…

Leaderboard > Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 717 Most Valuable Professional

#2
Michael E. Gernaey Profile Picture

Michael E. Gernaey 329 Super User 2025 Season 2

#3
Power Platform 1919 Profile Picture

Power Platform 1919 268

Last 30 days Overall leaderboard