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 / How to work with Polym...
Power Apps
Unanswered

How to work with Polymorphic lookup in CDS

(2) ShareShare
ReportReport
Posted on by 499

Recently, I come across a scenario, where I need to create a CASE record with Customer lookup. Since Customer lookup is a polymorphic type, couldn't be able to get it through directly. But found a way to complete this using Patch and Form control options. It is working as expected - let me know your thoughts in case of any simpler approach

 

  1. Since it is a combination of Contact and Account, we cannot directly use it in Forms or Patch operations
  2. This can be achieved in two ways (both require two different combo box controls on the form)
  3. Using Patch
  4. Using Form

Using Patch:

  1. Create a canvas app
  2. Add Cases, Accounts and Contacts entities from Data Sources
  3. Add a From Control and map it to Case entity
  4. Add required Data Cards to it (Do not include Customer field)
  5. Add a Radio Button
  6. Add Two Combo Boxes and name them cmbAccounts and cmbContacts. Select cmbAccounts control and update its “ITEM” property with Accounts entity and for cmbContacts use “Contacts” against its Item property.
  7. Place the combo boxes on top of another (basically first cmbAccounts and on top of it cmbContacts)
  8. Select Radio button and go to “On Select” event and add below expression

 

If(Radio2.Selected.Value="Accounts",Set(varCMBAccounts, true);Set(varCMBContacts,false),If(Radio2.Selected.Value="Contacts",Set(varCMBAccounts, false);Set(varCMBContacts, true)))

 

  1. Select Accounts Combo box-> Visible -> varCMBAccounts
  2. Select Contacts Combo box -> Visible -> varCMBContacts
  3. Now, on select of “Create Case” button – use the following expression to create a new Case Record

 

Patch (Cases, Defaults (Cases),{'Case Title':DataCardValue1.Text},{Subject:DataCardValue2.Selected},{Customer:If(Radio2.Selected.Value = "Accounts",
cmbAccounts.Selected, If(Radio2.Selected.Value = "Contacts",cmbContacts.Selected))});
ResetForm(Form1)

 

Using Form Control (Submit Form ()):

  1. Create a canvas app
  2. Add Cases, Accounts and Contacts entities from Data Sources
  3. Add a From Control and map it to Case entity
  4. Add required Data Cards to it and include Customer Data Card too
  5. Hide the Customer Data Card (Visible -> false)

Please follow the same steps above from 6 to 10.

Now, select the “Customer” Data Card on the Form and go to “Update” property and add

If(Radio2.Selected.Value = "Accounts",cmbAccounts.Selected, If(Radio2.Selected.Value = "Contacts",cmbContacts.Selected))

On “Create Case” button:

SubmitForm(Form1); ResetForm(Form1)

I have the same question (0)
  • Joel CustomerEffective Profile Picture
    3,224 on at

    Case customer is a tricky one--not too long ago it wasn't working when updating via Patch. Glad to see that it is now working.

  • timl Profile Picture
    36,383 Super User 2025 Season 2 on at

    Hi @krishnags 

    I think your solution looks great, and with the radio button, it provides a user friendly way for the user to switch between selecting contacts or accounts. Thanks for sharing your code!

  • SaiKrishnaGudluru Profile Picture
    499 on at

    @timl glad to hear it helps. 

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