Sub topic 7
Publishing a field and using it in UIs, reports, forms and APIs
This chapter covers what happens after you create a custom field in the Custom Fields and Logic app. It assumes you can open the app, have a field in draft state, and know what a business context is. It also assumes basic OData and CDS knowledge. A field that is only saved does nothing yet. Publishing makes it real in the system, and the usage switches decide where it shows up.
What publishing does
A custom field is first stored as a definition. While the field is unpublished, no database column exists for it, and no UI, report, form or API knows about it. Publishing starts a generation process. The system does these things:
- It adds a persistent field to the extension include of the database table behind the business context.
- It extends the CDS views and the released APIs that are tied to that context with the new field.
- It makes the field available to the usage options you selected, such as UI adaptation, reporting, form templates and email templates.
Because publishing changes the data model, it is not instant. The app shows a status for the field while generation runs. Treat publication like a small deployment, not like saving a form.
Before you publish
Check these points first, because several of them cannot be changed afterwards.
- Business context. The context decides which tables, views and APIs receive the field. Choosing the wrong one means creating a new field and deleting the old one.
- Type, length and decimals. After publication, you generally cannot change the data type or make the field shorter. Pick a length with room to grow.
- Label and description. Labels can be maintained in several languages. Add translations before users in other languages see the field.
- Usage options. Select the options you need now. You can usually add more later, but each change needs another publication.
The identifier of a published field
The system builds the technical name for you. It adds the YY1_ prefix, your field name, and a suffix taken from the business context.
Custom field ID pattern: YY1_<FieldName>_<suffix>
Example: YY1_CostCenterNote_PRD
The YY1_ prefix marks key user extensions. The suffix is generated by the system from the business context.You will use this name in API calls, CDS projections and report definitions, so write it down when you publish. The label is what users see. The technical name is what integrations see.
Using the field in UIs
A published field does not appear on a screen on its own. A key user adds it with UI adaptation:
- Open the Fiori app, such as Manage Sales Orders.
- Open the user menu and choose Adapt UI.
- Switch to adaptation mode and select a place on the page, such as a form group or a table.
- Choose Add Field and pick your field from the list of available custom fields.
- Save and publish the adaptation, or save it for yourself only.
Adaptations can be saved as personal or as system-wide changes. A system-wide change needs the key user role, and it is recorded in a transport request, which matters in the lifecycle chapter. Each Fiori app decides which parts of the page can be adapted, so a field may be addable on an object page but not in a list report filter. If the field is missing from the list, check three things. The field must be published and not still generating. The field must belong to the business context of that app. The app must support adaptation.
Using the field in reports
Reporting works because the CDS views that feed analytical apps are extended with your field during publication. To make a field usable in reports, select the reporting usage option before you publish. After publication:
- In apps such as Custom Analytical Queries and View Browser, the field appears as a regular element of the extended view.
- In a custom analytical query, you can add it as a dimension, such as a text or code field. You can add it as a measure only if it has a numeric or amount type.
- Value help for a code-list field comes from the code list you defined with the field.
Data you entered before publication is not retroactively filled. Existing records show an initial value, such as an empty string or zero, until a user or a process sets the field. Plan a data-fill step if reports must show history.
| Field type | Typical use in a query | Note |
|---|---|---|
| Text | Dimension, filter | Not summed |
| Code list | Dimension with value help | Texts come from the code list |
| Number | Measure | Aggregation settings are set in the query |
| Amount | Measure | Needs a currency reference field |
| Date | Dimension, filter | Often used for time-based grouping |
Using the field in forms and email templates
Form templates and email templates read from data sources, which are the same extended views that reporting uses. When you enable the form or email usage option, the field becomes a selectable data element in those tools. In a form template, open the template in the adaptation tool for output forms, find your field in the field list, and place it in the layout. For email templates, the field becomes available as a placeholder.
A field you add to a layout is shown only when the underlying document has a value. Test with a document that has the field filled and one that does not. The empty case often leaves a gap in the layout.
Using the field in APIs
Publishing a field extends the released OData APIs of its business context. The field is added to the entity as a property with its technical name. For a field in the sales document header context, the entity A_SalesOrder in API_SALES_ORDER_SRV gains a property such as YY1_CostCenterNote_SDH.
The following script reads a sales order with the custom field. It assumes a system that accepts basic authentication for the communication user. In practice, the user comes from a communication arrangement.
import os
import requests
host = os.environ["S4_HOST"] # for example https://my123456-api.s4hana.cloud.sap
user = os.environ["S4_USER"]
password = os.environ["S4_PASSWORD"]
url = f"{host}/sap/opu/odata/sap/API_SALES_ORDER_SRV/A_SalesOrder"
params = {
"$top": "5",
"$select": "SalesOrder,YY1_CostCenterNote_SDH",
"$format": "json",
}
response = requests.get(url, params=params, auth=(user, password), timeout=30)
response.raise_for_status()
for row in response.json()["d"]["results"]:
print(row["SalesOrder"], row.get("YY1_CostCenterNote_SDH"))Writes work the same way. Include the custom property in a POST or PATCH body with the standard properties. Two rules apply:
- The communication scenario that exposes the API must be active, and the communication user must be allowed to use it.
- Metadata is cached. If a new property does not appear, fetch
$metadataagain. A client that generated its model from an older$metadatadocument will ignore or reject the new property.
Where the field appears: a summary
| Place | What you must do | Common reason it does not show |
|---|---|---|
| Fiori UI | Use Adapt UI and add the field | App does not allow adaptation, or the context differs |
| Report | Enable the reporting option, then publish | Option was not selected before publishing |
| Form template | Enable form usage, then edit the template | Field is not placed in the layout |
| Email template | Enable email usage, then add the placeholder | Wrong data source for the template |
| OData API | Publish, then refresh `$metadata` | Cached metadata or an inactive scenario |
Changing a published field
You can still change some properties. Labels and descriptions can be edited. Usage options can be added. Changes to usage need another publication. You cannot reduce the length or change the data type. If a field is wrong, the safe path is:
- Create a new field with the correct definition.
- Move the data, for example with a report and a mass change, or with an API script.
- Switch UIs, reports and integrations to the new field.
- Delete the old field when nothing uses it.
The Custom Fields app shows where a field is used. Check this list before you delete anything, because removing a field that a form or query still references can break that object.
Troubleshooting publication
- Status stays in progress. Generation can take several minutes for tables with many dependent views. Refresh the app before assuming a failure.
- Publication failed. Open the error details. Typical causes are a naming clash, a missing authorization or a locked dependent object. Fix the cause and publish again. Publishing a field again is safe.
- Field visible in the app but empty in the API. The API may be on an older metadata cache, or the document was saved before the field existed.
- Field missing from the Adapt UI list. The field does not belong to the business context of the page, or its publication has not finished.
Exercise
You published a custom field with the reporting option off. A colleague wants it in a custom analytical query. What must you do, and what will the query show for existing documents?
Show answer
Edit the field, enable the reporting usage option, and publish again, because the extension of the CDS views happens during publication. After that the field is available in the query. Existing documents show the initial value (empty or zero) until the field is filled, since publication does not back-fill data.
Exercise
A client app calls APISALESORDERSRV and never receives YY1CostCenterNote_SDH, although the field is published. Name two checks.
Show answer
Refresh the cached $metadata so the client model includes the new property, and verify that the communication arrangement and user cover the API scenario. You can also confirm that the field's business context matches the entity, because a field from another context is not added to this API.