cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Hide UI.Facet dynamically w/ ABAP CDS annotcation

AustinKloske
Participant
0 Likes
1,377

I am attempting to show/hide UI facets using only ABAP CDS annotations with Fiori Element App Preview from eclipse (ADT). Our S/4 HANA on-premise 2023 system components. 

Screenshot 2025-04-08 at 11.12.30 AM.png

In the CDS projection view, I create a virtual element. Any boolean type other than 'abap_boolean' gives a deprecrated warning: 'Data Element xfeld is deprecated. Use Data Element ABAP_BOOLEAN instead', so we use abap_boolean. 

@EndUserText.label: 'Hide Section 1'
@UI.hidden: true
virtual hideSection1IsEnabled: abap_boolean,

 

In the metadata extension, we attempt to reference the virtual element but are given error 'Annotation value "hideSection1IsEnabled" must be of type 'Boolean'.@EndUserText.label: 'Hide Section 1' @ui.hidden: true virtual hideSection1IsEnabled: abap_boolean,  

  @UI.facet: [
  {
    parentId: 'Section1',
    id: 'SubSection1',
    type: #FIELDGROUP_REFERENCE,
    label: 'Sub Section 1',
    targetQualifier: 'DetailsGroup',
    hidden: 'hideSection1IsEnabled'
  },

__PRESENT

Screenshot 2025-04-08 at 11.17.10 AM.png

 

Accepted Solutions (0)

Answers (3)

Answers (3)

MioYasutake
SAP Champion
SAP Champion

@AustinKloske 

The annotation for dynamically hiding a header facet is as follows:

  {
    hidden: #('editActionIsEnabled'),
    label: 'Credit Limit Consumption',
    id: 'CreditLimitChartHeader',
    targetQualifier: 'CreditLimitChart',
    targetElement: '_CREDITLIMITDETAILS',
    type: #CHART_REFERENCE,
    purpose: #HEADER
  }

https://sapui5.hana.ondemand.com/#/topic/ca00ee45fe344a73998f482cb2e669bb

 

AustinKloske
Participant
0 Likes

I saw that in the documentation but it was unclear how to implement it using ABAP cds annotations. I think that 'editActionIsEnabled' refers to a xml property defined as Edm.Boolean. (https://github.com/SAP/open-ux-tools/blob/a5a6a14936119a90905d73d4dfacbf8672d09e93/packages/odata-se...). I created this post to hopefully get a solution that works as a ABAP CDS annotation. If it requires js or xml based development that will be done in BAS / outside of our ABAP system so be it. Hopefully as RAP and clean core add-ons become more popular more functionality becomes available through ABAP cds annotations.

AustinKloske
Participant
0 Likes

deleted.

ArunJacob
Active Participant
0 Likes
@ui.facet: [{
    parentId: 'Section1',
    id: 'SubSection1',
    type: #FIELDGROUP_REFERENCE,
    label: 'Sub Section 1',
    targetQualifier: 'DetailsGroup',
    //hidden: 'hideSection1IsEnabled'
}]

extend via manifest.json(say a details page):-

"sap.ui.controllerExtensions": {
  "sap.suite.ui.generic.template.ObjectPage.view.Details": {
    "controllerName": "<controller_name>"
  }
}

in the actual controller after rendering:-

onAfterRendering: function () {
        var oView = this.getView();
        var oModel = oView.getModel(); // Assuming you use default model
        var oContext = oView.getBindingContext();

        // Read the field `hideSection1IsEnabled`
        var bHideSection = oModel.getProperty("hideSection1IsEnabled", oContext);

        // Get the SmartForm or Section control (adjust ID)
        var oSection = oView.byId("SubSection1"); // Use actual section ID

        if (oSection) {
          oSection.setVisible(!bHideSection); // Hide or show based on logic
        }
      }
ArunJacob
Active Participant
0 Likes

Hi,

ADT expects a literal value(true/false), not reference.

To show/hide UI facets dynamically, I think custom logic at UI5 can be done.

Thanks,

Arun

 

AustinKloske
Participant
How would you toggle the UI.Hidden filter on/off if you can only set it with a literal value? Feels like a bug to not be able to pass a reference variable to me.