cancel
Showing results for 
Search instead for 
Did you mean: 

How to hide conditionally a facet on Create subpage of List report | CAP Node.js

0 Kudos
719

Hello, I was able to hide a facet(Fiori elements app) on the object page by:

1. define a virtual property for the projection in service.cds

2. setting the property to true/false based on a condition in the service.js file (after READ handler)

3. and passing it to UI.Hidden annotation of the facet in the Annotations

But I am not able to hide the facet when I am on the List report page and click the Create button, then the facet is vissible on that subpage for creating the new object.

Any ideas?

Thanks!

Pavel

View Entire Topic
Achieved it by using the following logic:

In ObjectPageExt.controller.js( list report's creation page is considered as an object page ), which needs to be mentioned in manifest.json like this:

"extends": {
            "extensions": {
                    "sap.suite.ui.generic.template.ObjectPage.view.Details": {
                        "controllerName": "appPath.ext.controller.ObjectPageExt"
                    }

on Init part of it(ObjectPageExt) I've got -

this.extensionAPI.attachPageDataLoaded(this._onPageDataLoaded.bind(this))

Then defined the _onPageDataLoaded function inside the same controller and wrote this logic:

_onPageDataLoaded: function (oEvent) {
                const bIsCreationPending = oEvent?.context?.oSyncCreatePromise && oEvent.context.oSyncCreatePromise?.isPending() //this returns true if you are currently on Creation page

                if (bIsCreationPending === true) {
                    const oView = this.getView()
                    const oModel = oView.getModel()

                    //Hide facet on Creation page if some logic is fulfilled, in my case reading some backend data and checking something
                    oModel.read('/entityProjectionNameDefinedInYourCdsService', {
                        success: function (data) {
                            if (data.something === true) {
                                const facet = oView.byId('com.sap.vocabularies.UI.v1.FieldGroup::FacetName-ComingFromTargetSectionOfTheFacetInAnnotations::Section')
//oView.byId - gets any object from the page, in this case the facet I need to hide.
//You can find the ID of the objects by browsing the tree on Elements tab in chrome debugger when stopped on your page.

                                facet.setVisible(false)
                                //this hides it
                            }
                        }.bind(this)
                    })
                }
            }