cancel
Showing results for 
Search instead for 
Did you mean: 

Dynamic @UI.Hidden in CDS Annotations

pmcfarling
Participant

Does anyone know how to dynamically set the @UI.Hidden annotation using CDS Annotations? I can do it with XML Annotations (<Annotation Term="UI.Hidden" Path="anXfeld">) and it works perfectly. Can't figure out how to do it with CDS. Seems @UI.Hidden can't use a path?

<Annotations Target="Metadata.xDSNxC_CM_CONTType">
    <Annotation Term="UI.FieldGroup" Qualifier="cont_checkboxes">
     <Record Type="UI.FieldGroupType">
      <PropertyValue Property="Data">
       <Collection>
        <Record Type="UI.DataField">
         <PropertyValue Property="Value" Path="fundingcontrol"/>
         <PropertyValue Property="Label" String="Funding Control"/>
        </Record>
        <Record Type="UI.DataField">
         <PropertyValue Property="Value" Path="extfundingsource"/>
         <PropertyValue Property="Label" String="Ext Funding"/>
         <Annotation Term="UI.Hidden" Path="fundingcontrol"/>
        </Record>
       </Collection>
      </PropertyValue>
     </Record>
    </Annotation>
   </Annotations>
View Entire Topic
pmcfarling
Participant

I figured this out by reverse engineering the generated XML annotations and comparing them to XML that I knew worked.

for somereason adding @UI.hidden: #(fieldname) didn't work putting it directly on the field. I had to add it to the fieldgroup annotation i.e.

  @UI.fieldGroup: [{    label: 'Funding Control',

                        qualifier: 'cont_checkboxes',

                        position: 130,

                        hidden: #(modcontrol)   }]

  fundingcontrol;

This will hide fundingcontrol if modcontrol is checked.

maheshpalavalli
Active Contributor

Thanks for sharing, Paul. It's some hidden/unreleased feature i guess 🙂

Such a simple and helpful solution.
Totally worked for me !
Thanks.

Andre_Fischer
Product and Topic Expert
Product and Topic Expert

Hi Paul,

Thank you very much for this post.

I would like to add that "modcontrol" must be of type boolean.

I first tried it with

virtual  HideLink            : abap.char( 1 ),

but this did not work.

Only after having changed the definition of my virtual field to

virtual  HideLink            : abap_boolean,

the field (that contains a URL) was hidden.

florian_halder
Participant
0 Kudos

Hi Andre Fischer,

do you know what the reason is that this is not done via the instance features of RAP, like read only etc.?

I find this rather impractical/unattractive that in the worst case I need a virtual element for each field which I want to hide, when they have different conditions.

Thanks in advance, Florian

mohr_andreas
Explorer
0 Kudos

Hey Florian,

did you found an answer for your question? I'm also curious why I can't use the dynamic feature control for hiding fields. It is really impractical to implement field control with SADL/virtual elements to hide fields and to implement the dynamic feature control for make fields read-only or mandatory. We have over 100 fields.

Did you get it working with virtual elements to hide a column in a table inside an ObjectPage? I didn't find any solution so far for this problem. It is only working for me to hide field inside the object page.

Thanks & Cheers
Andreas