cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
btonrich
Frequent Visitor

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 @btonrich ,

 

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
Super User
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. 

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"]. 

View solution in original post

Brilliant, this has worked thank you.

No problem, happy to help! 🙂 

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 @btonrich ,

 

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

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! 

 

 

 

 

 

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
UG GA Amplification 768x460.png

Launching new user group features

Learn how to create your own user groups today!

Community Connections 768x460.jpg

Community & How To Videos

Check out the new Power Platform Community Connections gallery!

M365 768x460.jpg

Microsoft 365 Collaboration Conference | December 7–9, 2021

Join us, in-person, December 7–9 in Las Vegas, for the largest gathering of the Microsoft community in the world.

Users online (1,517)