cancel
Showing results for 
Search instead for 
Did you mean: 

Smartfield: show ID and Description in both Read Only and Edit mode

afordham
Participant
2,608

Hi,

I'm going quietly mad trying to get the ID and Description of a bound property showing in both display mode and edit mode when using a Smartfield. Apologies for the length of the question, but I'm trying to show everything I've done so far in case someone can spot what's wrong.

I have an Interface CDS view which has association between an ID field - Function - and another view that provides the description of the Function ID:

define view ZI_FIS_SERVICE_ORDER
  as select from <myDatabaseTable> as ServiceOrder
  association [0..1] to ZI_FIS_Function as _FunctionText on $projection.Function = _FunctionText.Function {
      @ObjectModel.text.association: '_FunctionText'
      ServiceOrder.gewrk              as Function,
...
   _FunctionText, ... }

I then have a Consumption CDS view that repeats this text association annotation (maybe unnecessarily) and adds a value help

define view ZC_FIS_SERVICE_ORDER
  as select from ZI_FIS_SERVICE_ORDER as ServiceOrder
  association [0..1] to ZI_FIS_FunctionVH as _FunctionVH on $projection.Function = _FunctionVH.Function {
      @ObjectModel.text.association: '_FunctionText' 
      @Consumption.valueHelp: '_FunctionVH'
      ServiceOrder.Function,
...
      _FunctionVH,
      _FunctionText, ...}

When I create a service (SEGW RDS), I get a new, automatically generated property in my entity called Function_Text which gets associated with the Function property in the $metadata

<Property Name="Function" ... sap:text="Function_Text" .../>
<Property Name="Function_Text" .../>

and the Function description gets correctly populated in the response, e.g.

<d:Function>CFGOO</d:Function>
<d:Function_Text>Central Functions GOO</d:Function_Text>

So far, so good.

I now want to put a Smartfield on a page that shows both the Function ID and the Function Text in both display and edit mode.

In an attempt to see how all the different options work, I have put 3 smartfields on the screen, all bound to the Function property and all with displayBehaviour="idAndDescription":

1. Read Only

2. Editable with textInEditModeSource="NavigationProperty"

3. Editable with textInEditModeSource="ValueList".

<smartField:SmartField value="{Function}" id="idFunctionReadOnly" visible="true" editable="false">
	<smartField:configuration>
		<smartField:Configuration displayBehaviour="idAndDescription"/>
	</smartField:configuration>
</smartField:SmartField>									

<smartField:SmartField value="{Function}"...editable="true" textInEditModeSource="NavigationProperty">
	<smartField:configuration>
		<smartField:Configuration displayBehaviour="idAndDescription"/>
	</smartField:configuration>
</smartField:SmartField>
									
<smartField:SmartField value="{Function}" ... editable="true" textInEditModeSource="ValueList">
	<smartField:configuration>
		<smartField:Configuration displayBehaviour="idAndDescription"/>
	</smartField:configuration>
</smartField:SmartField>

The annotation for com.sap.vocabularies.Common.v1.Text is not generated in either my $metadata or the Annotations file (for some reason), so I'll start without it. This gives the following on the UI:

So the read only field must be getting the description from the Function_Text field, as specified in the $metadata, as there's no annotation to tell it go anywhere else. The ValueList option has put in an additional OData call to the CDS view and successfully retrieved the description, but the NavigationProperty one has not found the description.

If I put the following in the annotations file (so making the path a property in the same entity):

<Annotations Target="Metadata.ZC_FIS_SERVICE_ORDERType/Function">
	<Annotation Term="Common.Text" Path="Function_Text"/>
</Annotations>

I get the following on the UI (I'm omitting the ValueList one because it always works!):

So the read only field is getting the description from somewhere (I don't know whether it's using the $metadata or the new annotation) but the NavigationProperty still has just the ID

When I change the annotations file to use a path to the entity that contains the Function text:

<Annotations Target="Metadata.ZC_FIS_SERVICE_ORDERType/Function">
	<Annotation Term="Common.Text" Path="to_FunctionText/Description"/>
</Annotations>

that breaks the read only field, but there's still no description in the NavigationProperty field:

So this looks to me like the annotation is being taken into account by the read only field (and maybe the NavigationProperty field as well), but it's not working.

Why don't I use the ValueList version if it always works? Two reasons: firstly, the value help CDS only returns a subset of the Function IDs since some are now obsolete, but I still want the description of the Function shown for old records; secondly, the ValueList version puts in an extra OData call to the backend even though the Function description has already been returned to the UI by the GET on the main entity, so that seems a waste (and I have a lot of fields that I want to display like this).

So, finally, does anyone have any ideas as to what's wrong? I suspect I'm missing an annotation somewhere in the CDS view, as I would have expected the com.sap.vocabularies.Common.v1.Text XML annotation to have been generated by the Gateway service, but it hasn't been. I'm stuck!

Many thanks in advance,

Andrew

Accepted Solutions (0)

Answers (0)