cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
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
Highlighted
Resolver II
Resolver II

Re: Default value for lookup via a CDS relationship

Hi btonrich, 

 

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

View solution in original post

Highlighted
Resolver II
Resolver II

Re: Default value for lookup via a CDS relationship

 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
Highlighted
Resolver II
Resolver II

Re: Default value for lookup via a CDS relationship

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. 

Highlighted
Frequent Visitor

Re: Default value for lookup via a CDS relationship

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

Highlighted
Resolver II
Resolver II

Re: Default value for lookup via a CDS relationship

Hi btonrich, 

 

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

View solution in original post

Highlighted
Frequent Visitor

Re: Default value for lookup via a CDS relationship

Brilliant, this has worked thank you.

Highlighted
Resolver II
Resolver II

Re: Default value for lookup via a CDS relationship

No problem, happy to help! 🙂 

Highlighted
Frequent Visitor

Re: Default value for lookup via a CDS relationship

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.

Highlighted
Resolver II
Resolver II

Re: Default value for lookup via a CDS relationship

 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

Highlighted
Frequent Visitor

Re: Default value for lookup via a CDS relationship

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! 

 

 

 

 

 

Highlighted
Frequent Visitor

Re: Default value for lookup via a CDS relationship

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
Community Conference

Power Platform Community Conference

Find your favorite faces from the community presenting at the Power Platform Community Conference!

Watch Now

Experience what’s next for Power Apps

See the latest Power Apps innovations, updates, and demos from the Microsoft Business Applications Launch Event.

Power Platform ISV Studio

Power Platform ISV Studio

ISV Studio is designed to become the go-to Power Platform destination for ISV’s to monitor & manage published applications.

secondImage

Power Platform 2020 release wave 2 plan

Features releasing from October 2020 through March 2021

Users online (6,283)