cancel
Showing results for 
Search instead for 
Did you mean: 

Dynamic @UI.Hidden in CDS Annotations

pmcfarling
Participant
13,363

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>

Accepted Solutions (1)

Accepted Solutions (1)

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

Andreas_M
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

Answers (3)

Answers (3)

GManousaridis
Participant

Hey Paul,

I tried to implement your solution but with no luck.. I don't know what it was that I didn't see..

Hopefully this alternative worked! Hope it helps!

Cheers,

George

pmcfarling
Participant

That seems like a lot of work for a simple thing. Think something not obvious must have been going on.

What you describe in your blog is exactly what the framework does under the hood when you mark a field as 'EXTERNAL_CALCULATION' (Though I see there was a technical reason you couldn't do that).

If you have

 @ObjectModel.enabled:'EXTERNAL_CALCULATION'
 somefield,

on your odata service a new field will be created called "somefield_fc" and "somefield" will use "somefield_fc" as it's field control. (Note, if you're using SEGW project as opposed to @Odata.publsh:true you MUST regenrate your project after marking any field as EXTERNAL_CALCULATIOn or the new *_fc field wont be available)

<Property Name="modnumber" Type="Edm.String" MaxLength="35" sap:display-format="UpperCase" sap:field-control="modnumber_fc" sap:label="Modification Number" sap:quickinfo="Mod Number"/>

The @UI.hidden:#(someval) does work and is very lightly documented.

But, at the end of the day, it just translates to the XML annotation "<Annotation Term="UI.Hidden" Path="hidemod"/>" which is also another way to accomplish this in a local annotation file.

<Record Type="UI.DataField"><PropertyValue Property="Label" String="Authorized Unplanned Vaue"/><PropertyValue Property="Value" Path="authunvalue"/><Annotation Term="UI.Hidden" Path="hidemod"/></Record>

I use My Inbox in a few place, I might see if I can make it work and report back.

GManousaridis
Participant
0 Kudos

Oh I see, +1 for the automatic generation of somefield_fc.

Yes if you could please provide some more info on @UI.Hidden, that would be great!

maheshpalavalli
Active Contributor

Can u try this and check.

https://help.sap.com/viewer/cc0c305d2fab47bd808adcad3ca7ee9d/7.51.7/en-US/ff67efc37b154f1e88a2f44d26...

Use EXTERNAL_CALCULATION and use annotation readOnly.

But in the determination, call property helper method "set_attribute_enabled".

Thanks,
Mahesh

pmcfarling
Participant
0 Kudos

Thanks, I’m aware of that but I need hidden. Fields would make no sense in certain contexts. I’m also aware of to do it by adding the annotations via ABAP ion the MPC_EXT class but I’m trying to avoid that.

maheshpalavalli
Active Contributor
0 Kudos

pmcfarling Yeah, but there are 2 other methods for read only and mandatory and I believe enabled is to make them visible and invisible.

maheshpalavalli
Active Contributor
0 Kudos

pmcfarling I guess you cannot use hidden annotation from cds, the way I think of is to use enabled method in determination.

pmcfarling
Participant
0 Kudos

yes, it appears set_attribute_enabled will work. It appears I have to use EXTERNAL_CALCULATION on the enabled annotation.

i.e. @ObjectModel.enabled: 'EXTERNAL_CALCULATION'

I will try it and let you know

0 Kudos

If you're using the CAP framework, it should look like this:

Note that it will only accept a boolean field.

FieldGroup #General : {Data : [
        {
            Value : AUART,
            Label : '{i18n>AUART}'
        },
        {
            Value : VKORG,
            Label : '{i18n>VKORG}',
            ![@UI.Hidden] : IsActiveEntity
        },
        {
            Value : VTWEG,
            Label : '{i18n>VTWEG}'
        },
        {
            Value : SPART,
            Label : '{i18n>SPART}'
        }
    ]},


hatrigt
Participant
0 Kudos

briannicholas May I know from where we can set the flag in IsActiveEntity?

For me, In CAP application, I have list report in which I have to hide a column based on the value derived in CAP Service implementation JS file. Any Idea how can we achieve this?