Skip to main content

Notifications

Power Apps - Microsoft Dataverse
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?

Categories:
  • Ram Prakash Profile Picture
    Ram Prakash 5,154 on at
    Re: dynamically change view on polymorphic form field

    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

  • Bipin D365 Profile Picture
    Bipin D365 971 on at
    Re: dynamically change view on polymorphic form field

    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/

     

  • Devikumari Krishna Profile Picture
    Devikumari Krishna 988 on at
    Re: dynamically change view on polymorphic form field

    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

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

Microsoft Kickstarter Events…

Register for Microsoft Kickstarter Events…

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Announcing Forum Attachment Improvements!

We're excited to announce that attachments for replies in forums and improved…

Leaderboard

#1
WarrenBelz Profile Picture

WarrenBelz 145,636

#2
RandyHayes Profile Picture

RandyHayes 76,287

#3
Pstork1 Profile Picture

Pstork1 64,942

Leaderboard

Featured topics