Value Helps
A property with a value list in the $metadata gets the matching Atscript UI value help: a searchable picker in forms and in the filter bar, narrowed by the form's values, filling the fields the list returns, with the columns the list names. Fixed values become dropdowns, and a code shows its text. Nothing is configured by hand: the generator writes the annotations, both hosts serve them.
@meta.label 'Sold-to Party'
@ui.valueHelp Customer, 'CustomerId', `Country = Order.Country`
@ui.valueHelp.fill 'SoldToPartyName', 'CustomerName'
@ui.valueHelp.column 'CustomerId'
@ui.valueHelp.column 'CustomerName'
@ui.valueHelp.column 'Country'
@ui.valueHelp.column 'City'
@ui.valueLabel 'SoldToPartyName'
SoldToParty: stringThis is what the generator writes for the SoldToParty of a sales order whose value list reads CustomerSet, takes the order's country as an input, returns the customer's name, and shows four columns:
@ui.valueHelp Customer, 'CustomerId', …: the picker lists customers, and a pick stores the row'sCustomerIdinSoldToParty. In a form, the condition lists only the customers of the order'sCountry.@ui.valueHelp.fill 'SoldToPartyName', 'CustomerName': a pick also writes the picked customer'sCustomerNameinto the order'sSoldToPartyName. The first argument is the field of this model that gets written, the second the field of the picked row.@ui.valueHelp.column: the columns of the picker dialog, in order.@ui.valueLabel 'SoldToPartyName': table cells and read-only fields show the name with the code.
Standard Atscript UI annotations
These are Atscript UI's own value-help annotations, not an OData extension: a model you write by hand for Atscript DB uses exactly the same ones, and its screens behave the same. See A pick fills other fields in the Atscript UI guide.
From value list to annotations
The generator reads Common.ValueList (v4, and the v2 Annotations blocks inside the $metadata) and the v2 sap:value-list attribute. A property with several lists gets the unqualified one, else the first.
| In the value list | In the generated type |
|---|---|
CollectionPath, and the Out / InOut parameter of the property itself | @ui.valueHelp <EntitySet type>, '<ValueListProperty>' |
In / InOut of another property | a condition <ValueListProperty> = <Host>.<LocalDataProperty> in the binding's filter |
Constant | a condition <ValueListProperty> = <literal> in the binding's filter |
Out / InOut of another property | @ui.valueHelp.fill '<LocalDataProperty>', '<ValueListProperty>' |
| the text of the picked field, when the list returns it | @ui.valueHelp.fill '<the property's text>', '<that text>' |
the properties the list names (not Constant) | @ui.valueHelp.column '<ValueListProperty>', in order; none when it names only the bound one |
ValueListWithFixedValues, sap:value-list="fixed-values" | @ui.type 'select' |
Common.Text, sap:text, with UI.TextArrangement | @ui.valueLabel '<text property>' (see Texts next to codes) |
| the text of the list entity set's single key | @ui.dict.label on that text: the picker lists its rows by it (see Picker rows) |
The list's entity set must be part of the generated model: a list over a set you left out with entitySets binds nothing. The binding names the set's interface (Customer); the host resolves it to a URL.
Narrowing by the form's values
An In parameter becomes a condition on a field of the host interface: Country = Order.Country narrows the customers to the order's country. Atscript UI reads the host field by name in every form the binding reaches, and only in forms: a table's filter bar lists every value.
See it live
Open coffee 17 in the browser app: the Region picker lists only the regions of its Origin. Code: src/generated/roastery.as.
Filling other fields
A pick writes the list's Out and InOut parameters into the form, one @ui.valueHelp.fill '<field of this model>', '<field of the picked row>' each. SAP services often give a property the same name on both sides of the parameter, so generated models commonly read @ui.valueHelp.fill 'CustomerName', 'CustomerName': the picked customer's CustomerName is written into the order's own CustomerName. A text the service computes (a read-only field) is filled too, so the form shows the name at once, before the save. Clearing the field clears only the fill targets that still hold its last pick.
A property the service computes carries no length or format constraint (@expect.*) in the generated type: a picked text longer than the declared MaxLength does not block the save.
See it live
Open order 1091 in the browser app and pick another Café: the Ship-to city follows. Code: src/generated/roastery.as.
Columns
The properties the list names become the picker's columns, in the list's order. A list over a composite key that names the other key members as columns shows them next to each row, so rows with the same code tell apart.
Fixed values
A list flagged as fixed values becomes @ui.type 'select': a dropdown in forms that loads the list once, and a checklist in the filter bar. A dropdown commits a value, not a row, and shows no columns: where the rest of a composite key is pinned only by a host field or told apart only by columns, the generator keeps the search picker instead.
Texts next to codes
Common.Text (v4) or sap:text (v2) names the property that holds a code's text. With a string property next to the code, the code gets @ui.valueLabel, and Atscript UI shows the text with the code in table cells and read-only fields:
UI.TextArrangement | Generated | Shown as |
|---|---|---|
TextFirst (default) | @ui.valueLabel 'CustomerName' | text (code) |
TextLast | @ui.valueLabel 'CustomerName', 'keyText' | code (text) |
TextOnly | @ui.valueLabel 'CustomerName', 'text' | text |
TextSeparate | nothing | the code |
On a code with a value help, @ui.valueLabel is written only when a pick fills the text: otherwise the text would go stale after a pick. A text reached through a navigation (to_Customer/Name) is not placed and is listed in the trailer.
See it live
The Status filter on Orders in the browser app is a checklist of the service's statuses, each with its text. Code: src/generated/roastery.as.
Picker rows
A picker lists the rows of its entity set by the field marked @ui.dict.label. When the entity type has a single key property whose text (Common.Text, sap:text) is a string property of the same type, that property gets @ui.dict.label, whatever its arrangement: a picker over Products lists Brisk Hammer, not the first string property (SKU-0001). A composite key, or a key without such a text, leaves the label to Atscript UI's fallback, the first string property that is not a key. No @ui.dict.descr is generated.
What is not bound
Each of these leaves the property without a value help (or without that part of it) and is listed at the end of the .as file:
- a list whose entity set is in another service (
CollectionRoot), or whose mapping is in an OData v2 annotation document outside the$metadata; - the lists after the first of a property;
- a list that does not name the property in an
OutorInOutparameter; - a list that would show a value more than once: the property is not the list's whole key, and another key member is neither pinned (by a constant, or a host field the pick writes back) nor named as a column;
- a parameter whose local property is not a single primitive property next to the bound one (a path such as
to_Header/Country), or of another type than the list property, and a constant that does not read as a value of the list property's type.
A missing value help is never an error. Where you need one the generator cannot write, add @ui.valueHelp in an annotate block of your own (see Enrich the generated types).
Value-help services
On RAP v4 services of SAP S/4HANA® a property names its value list by reference: Common.ValueListReferences holds the URL of the $metadata of a separate value-help service, relative to the service's own, such as
../../../../srvd_f4/sap/zdemo_customer_vh/0001;ps='srvd-zdemo_vh_orders-0001';va='…customerid'/$metadataAt build time
atscript-odata fetch reads the document of each property's first reference and saves it next to the metadata with a manifest:
src/odata/sales.xml
src/odata/sales.value-helps.json
src/odata/sales.value-helps/zdemo_customer_vh.customerid.xml
src/odata/sales.value-helps/zdemo_country_vh.country.xml
…The plugin reads the manifest beside a service's metadata file by itself. Documents saved some other way are named by reference, exactly as the $metadata writes it, in the valueHelps option; an entry there wins over the manifest's:
odataPlugin({
services: [
{
name: "sales",
metadata: "odata/sales.xml",
valueHelps: {
"../../../../srvd_f4/sap/zdemo_country_vh/0001;ps='…';va='…country'/$metadata":
"odata/vh/country.xml",
},
},
],
});A property then gets the value help of its first reference's document, by the same rules as a list in the service's own $metadata. Each value-help entity set a binding targets becomes an interface of the same .as file, marked with its service:
@db.table 'ZDEMO_CUSTOMER_VH'
@db.space 'sales'
@odata.valueHelpService '../../../../srvd_f4/sap/zdemo_customer_vh/0001'
@meta.label 'Customers'
export interface ZDEMO_CUSTOMER_VHType {
@meta.id
@meta.label 'Customer'
@expect.maxLength 10
Customer: string
// …
}Properties whose references lead to one value-help service share its interface. Only the sets a binding targets are emitted. Until a reference has a document, the trailer lists it with the reference to copy.
The model module holds the value-help services and their roots, and the digest of each document. Hand the model module to the host: a model parsed from the $metadata alone has no value-help services.
At runtime
The hosts read the value-help documents the build recorded on every connect, together with the $metadata, in the same language and with the same options and credentials (see Live Metadata). A document that changed, or one the build could not read that reads now, takes the slow path. A document that cannot be read leaves its properties without a value help; it fails nothing. On a RAP service that is one read per document on every connect.
Where the picker reads from
A binding names an interface; the host gives that interface a URL (db.http.path), and Atscript UI reads the picker's rows there.
- Browser client. Connecting a service gives every entity set type of it its URL, value-help service sets included (
/odata/sales/<encoded value-help service>/<EntitySet>, which reads the set at the value-help service's root with the session of the service). Nothing to declare. See Browser Client. - Moost server. Moost DB gives a type the URL of the one controller that serves it. A value help appears when its target entity set has a controller.
valueHelpControllers(space, { prefix, base, own })declares them from the live types afterspace.connect(): every value-help service set, or withownevery target of the types your controllers serve, value-help sets only the live service has included. A target nobody serves gets no URL, and the field gets no picker, without a warning. See Value-help controllers.
Foreign keys work the same way: a property with @db.rel.FK (see Relations) gets Atscript UI's foreign-key picker over the target set, served by the same URL.
Your own models next to OData sets
A model of your own (an Atscript DB table of your database, a form type) binds a value help with the same annotations, to an OData type or the other way round:
// src/models/delivery.as
import { Customer } from '../odata/sales'
@db.table 'deliveries'
export interface Delivery {
@meta.id
id: number
@ui.valueHelp Customer, 'CustomerId'
@ui.valueHelp.fill 'customerName', 'CustomerName'
customerId: string
customerName?: string
}The picker needs its target's URL, from the host that serves the target:
- Moost server: the easier setup for mixing. Your own controllers and the OData controllers run in one application, and Moost DB gives every type it serves its URL, in both directions:
Deliverypicks fromCustomerSet's controller, an OData type from your table's. - Browser client: the factory gives the OData types their URLs. For an OData type that binds one of your tables, give that table a literal URL,
@db.http.path '/api/warehouses'onWarehouse, since nothing in the browser serves it. The other direction needs a server: your own server's/metaknows no URL for an OData type, so a binding from your table to an OData set gets no picker in the browser.
DOs and DON'Ts
- Serve every entity set a value help targets (server:
valueHelpControllers; the browser factory registers them) — don't expect a picker over a set nobody serves. - Hand the generated model module to the host — don't parse the
$metadataalone when the service uses value-help services. - Keep the value-help folder and manifest next to the metadata file, and commit them — don't rename the saved documents by hand.
- Check the trailer for value lists that were not bound — don't assume the second list of a property is used.
- Add a missing value help with an
annotateblock — don't edit the generated file.
See also
- Atscript UI: references and value help: how the picker, fills and columns behave.
- Generating Models: the plugin options and the trailer.
mergeValueHelps,valueHelpReferences: the same merge for a model of your own.