cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Anonymous
Not applicable

Default value for lookup via a CDS relationship

Hi,

 

I have 2 entities joined together via a relationship lookup. In my edit form, the form correctly creates a drop down field with the available selections from my joined entity table. The items property is set as: Choices([@'Feed Distributions'].crb25_FeedBin)

 

I need to set a default value to this drop down field e.g. "AFP3" however this errors advising:

 

The property on this control expects record values. The rule produces text values which are not compatible.

 

Which formula should I use to calculate the default value?

 

Many thanks,

Richard

2 ACCEPTED SOLUTIONS

Accepted Solutions

Hi btonrich, 

 

Try setting the DefaultSelectedItems property to ["AFP3"]. 

View solution in original post

 Hi @Anonymous ,

 

Sorry about that, the method I mentioned will only work for simple arrays/lists containing single values, not complex types. 

 

Try using Lookup, I tested this and confirmed it worked with one of my custom entities that has Contact as the lookup, defaulting it to a Full Name of a certain contact, then submitted the Edit form which persisted without any error.

 

For your scenario, it should look something like this (I am assuming 'Feed Bin' is the field name on the Feed Bins entity). Let me know if this works, if not, please attach a sample screenshot so I can better assist.

 

LookUp(Choices([@'Feed Distributions] .crb25_FeedBin), 'Feed Bin' = "AFP3")

View solution in original post

9 REPLIES 9
ChrisPiasecki
Dual Super User
Dual Super User

Hi Richard, 

 

You could use Filter on the choices wrapped in the First function:

 

First(Filter(Choices([@'Feed Distributions] .crb25_FeedBin), "AFP3" in '<FeedBinDisplayName>'))

 

Replace <FeedBinDisplayName> with the name of the field on the related Feed in entity that afp3 value would reside in. 

Anonymous
Not applicable

Hi there, thanks for your quick reply. Unfortunately this did not work.

 

The entity 'Feed Distributions' is related to the entity 'Feed Bins'.
The primary name for 'Feed Bins' is called 'Feed Bin' and there is a corresponding related field called Feed Bin in the Feed Distributions entity.
The example feed bin name is "AFP3" which I would like it set to as a default from the Feed Bin entity.

I hope this makes sense! Do you have any further suggestion with this additional info?

 

Thanks,

Richard

Hi btonrich, 

 

Try setting the DefaultSelectedItems property to ["AFP3"]. 

Anonymous
Not applicable

Brilliant, this has worked thank you.

No problem, happy to help! 🙂 

Anonymous
Not applicable

Hi @Cpiaseki, on closer inspection, although the default text of the drop down can be changed using your method, it is not recognised in the data when you submit the form. I suspect its the Default option that needs code rather than DefaultItemSelected.

Do you have any further ideas on how to resolve this? 

 

Reason for requiring this is I need to set the default option according to a barcode scanner which is used to scan the feed bins.

 Hi @Anonymous ,

 

Sorry about that, the method I mentioned will only work for simple arrays/lists containing single values, not complex types. 

 

Try using Lookup, I tested this and confirmed it worked with one of my custom entities that has Contact as the lookup, defaulting it to a Full Name of a certain contact, then submitted the Edit form which persisted without any error.

 

For your scenario, it should look something like this (I am assuming 'Feed Bin' is the field name on the Feed Bins entity). Let me know if this works, if not, please attach a sample screenshot so I can better assist.

 

LookUp(Choices([@'Feed Distributions] .crb25_FeedBin), 'Feed Bin' = "AFP3")

Anonymous
Not applicable

Thank you for looking at this again! I feel that this issue is crucial to using the CDS as a relational database.

I have tried the method of lookup before and its not working. I suspect something else may be going on but please see a few screen shots.

btonrich_0-1600587965628.png

btonrich_1-1600588044665.png

btonrich_2-1600588254553.pngbtonrich_3-1600588669545.png

btonrich_4-1600588723682.png

btonrich_5-1600588771729.png

Please note the field "Feed Bin" on Feed Distribution is the current live field and is not connected to the relationship. Feed Bin RL is the feed connected to the relationship which im using as a test before going live when it works.
One thing which looks odd to me is when I go to properties and click "Depends on" and it shows this. The options dont change to something logical. But the settings havent been applied.

btonrich_7-1600589130421.png

Thank you for your help! 

 

 

 

 

 

Anonymous
Not applicable

Ahh I have it working now. Your formula works in the defaultitemselected field and not the default field.


Thanks again for your help!

Helpful resources

Announcements
Power Platform Conf 2022 768x460.jpg

Join us for Microsoft Power Platform Conference

The first Microsoft-sponsored Power Platform Conference is coming in September. 100+ speakers, 150+ sessions, and what's new and next for Power Platform.

Power Platform Call June 2022 768x460.png

Power Platform Community Call

Join us for the next call on June 15, 2022 at 8am PDT.

PA Virtual Workshop Carousel 768x460.png

Register for a Free Workshop

This training provides practical hands-on experience in creating Power Apps solutions in a full-day of instructor-led App creation workshop.

PA.JPG

New Release Planning Portal (Preview)

Check out our new release planning portal, an interactive way to plan and prepare for upcoming features in Power Platform.

Users online (2,282)