lookupField from a KeyValueCollection showing entity names and not the field value?

I have a KeyValueCollection/Loader:

<keyValueCollection id="orderSourceDc">
    <loader id="orderSourceDl">
            <![CDATA[select distinct e.orderSource
                             from rade_OrderStats e
                             order by 1]]>
         <property datatype="string" name="orderSource"/>

I have a lookupField defined on this KeyValueCollection:

<lookupField id="lookupOrdOrderSource"
        align="TOP_LEFT"  nullOptionVisible="false"
        optionsContainer="orderSourceDc" property="orderSource"/>

When I open the field and view it, I get this:

Why don’t I see the orderSource values? Why do I see entity names?


Your LookupField doesn’t know what property to use to display items’ caption. Define the captionProperty attribute, e.g. captionProperty="orderSource".


Thank you! That was it. Strangely, I have two other fields based on regular Entity Collections and not a KeyValueCollection. In both of those I defined “property” and not “captionProperty”. They worked just fine.

However, for consistency, I changed my other lookup fields from “property” to “captionProperty” for the dropdown values from the optionsContainer.

Why is a KeyValueCollection different from a regular Entity Collection in this way?

In fact, the property attribute is always used together with the dataContainer attribute and has no effect when it’s used with optionsContainer.

KeyValueCollectionContainer are designed to work with KeyValueEntity which has no instance name, so you need to define the captionProperty attribute.

OK, got it. Thanks again.