Smart Field with Value Help using Annotations
In this blog, I am going to discuss how I have implemented smart field with Value help for Commodity code using Annotations.
Working of Smart Field
There are two way to enter value in commodity code smart field .
- Value Help Suggestion
- Value Help F4
Value help Suggestion
On directly entering value in the smart field, it starts suggesting the various commodity codes with description to select from the list.
From the suggestions list we can select the desired Commodity Code which would get populated in the smart field.
Value Help F4
On pressing F4 we will get a Popup of value help with empty list
After pressing Go button with or without giving search criteria it will load the commodity codes in to the list.
From this list we can select required commodity code. The selected commodity code would get populated in the commodity code smart field.
Implementation of smart field
It requires two entity one base entity and other for commodity code.
POLineItem entity have a property called CategoryId with sap:label as Commodity Code for which smart field needs to be given.
CategoryF4 entity have two properties.
- CategoryId with sap:label as Commodity Code
- CategoryText with sap:label as Commodity Code Description
For smart field to be editable base entityset i.e. PoLineItemSet must be updatable true.
CategoryId field is bound in view.xml with the smart Field control.
In OData Metadata, we use following annotation to tell the Framework that the UI element which is bound to “CategoryId” field in the model should render as value list.
In the above snip
‘1’ denotes the target path for which Value list to be given i.e. for CategoryId in POLineItem entity. Here we are using <Annotation Term=”com.sap.vocabularies.common.v1.ValueList”> for value help.
‘2’ denotes the CollectionPath , here the entityset to be given from where the list of categories are coming i.e. CategoryF4Set.
‘3’ denotes the search bar which is available in popup.
‘4’ denotes the Record, here it is ValueListParameterOut which will act as key which would get populated in the smart field after selecting from the list.
‘5’ denotes the LocalDataProperty , the field name of POLineitem for which value list is given.
‘6’ denotes the ValueListProperty, the key field of CategoryF4.
‘7’ denotes the Record, here it is ValueListParameterDisplayOnly, So it would be visible in the suggestion list and value help popup alongwith CategoryId for display purpose only.