Technical Articles
Fiori Elements – Object Page Table items: Context-based edit-ability
This blog post is to show how to make an item of an Object Page table editable or non-editable based on the context of the item itself.
The example is based on OData service version 2.0 metadata annotation. But applicable annotation for OData v4.0 is also mentioned.
The reference is taken from SAP documentation: Enabling Action Buttons in Tables on the Object Page
Update: For OData services built using ABAP Programming model for SAP Fiori, i.e., CDS view with BOPF enabled, there is another alternative approach to whatever depicted in this blog post to achieve the same (except ‘create’ entity operation). CDS annotation @ObjectModel has a variant ‘EXTERNAL_CALCULATION’ to achieve dynamic control over edit-ability/delete-ability of the entity based on condition. One needs to use methods SET_NODE_UPDATE_ENABLED or SET_NODE_DELETE_ENABLED of BO node determination implementation class as applicable.
Please refer here for more details on how to do this.
Thanks to Sitakant Tripathy for pointing this out.
@ObjectModel: {
transactionalProcessingEnabled: true,
...
createEnabled: true | false -- no dynamic entity control support for creation operations
deleteEnabled: 'EXTERNAL_CALCULATION'
updateEnabled: 'EXTERNAL_CALCULATION'
...
}
define view <ViewName>
as select from <data_source>
{
...
}
Steps:
- The OData service in this example is created using ‘Reference Data Source’ option in SAP OData Service builder (SEGW). Following is a snippet of the item CDS entity which will be represented as a table in the ui of object page.
- Add following lines of code in method DEFINE of the MPC_EXT class.
METHOD define.
DATA:
lr_entity TYPE REF TO /iwbep/if_mgw_odata_entity_typ.
super->define( ).
DATA(lr_entityset) = model->get_entity_set( 'ZCDS_I_SOS_HOME_ITEM' ).
DATA(lr_anno) = lr_entityset->create_annotation( 'sap' ).
IF lr_anno IS BOUND.
lr_anno->add( iv_key = 'updatable-path' iv_value = 'zactive' ).
lr_anno->add( iv_key = 'deletable-path' iv_value = 'zactive' ).
ENDIF.
...
ENDMETHOD.
Here, property ‘zactive’ is a boolean field of the same entity type and controls the edit-ability.
Please note that the OData service in my case is of version 2.0. For OData v4.0, one may use local annotation too.
<Annotations Target="ZFIAP_SOS_HOME_SRV.ZFIAP_SOS_HOME_SRV_Entities/ZCDS_I_SOS_HOME_ITEM">
<Annotation Term="Capabilities.UpdateRestrictions">
<Record Type="Capabilities.UpdateRestrictionsType">
<PropertyValue Property="Updatable" Path="zactive"/>
</Record>
</Annotation>
</Annotations>
This will result in OData service metadata like below:
<EntityContainer Name="ZFIAP_SOS_HOME_SRV_Entities" m:IsDefaultEntityContainer="true" sap:supported-formats="atom json xlsx">
<EntitySet Name="ZCDS_C_SOS_HOME_TP" EntityType="ZFIAP_SOS_HOME_SRV.ZCDS_C_SOS_HOME_TPType" sap:creatable="false" sap:deletable="false" sap:content-version="1"/>
<EntitySet Name="ZCDS_I_SOS_HOME_ITEM" EntityType="ZFIAP_SOS_HOME_SRV.ZCDS_I_SOS_HOME_ITEMType" sap:content-version="1" sap:deletable-path="zactive" sap:updatable-path="zactive"/>
<AssociationSet Name="assoc_D9749EB9F873E67DF6F0EBC9B059C454" Association="ZFIAP_SOS_HOME_SRV.assoc_D9749EB9F873E67DF6F0EBC9B059C454" sap:creatable="false" sap:updatable="false" sap:deletable="false" sap:content-version="1">
<End EntitySet="ZCDS_C_SOS_HOME_TP" Role="FromRole_assoc_D9749EB9F873E67DF6F0EBC9B059C454"/>
<End EntitySet="ZCDS_I_SOS_HOME_ITEM" Role="ToRole_assoc_D9749EB9F873E67DF6F0EBC9B059C454"/>
</AssociationSet>
</EntityContainer>
Notice the sap:deletable-path and sap:updatable-path annotations applied to the entityset ZCDS_I_SOS_HOME_ITEM in the example above. For more information on sap annotations for OData v2.0, please refer to this page.
3. Then the UI application is created using Fiori Elements template for ‘List Report Floorplan’.
For details on how to design and develop a fiori elements app using object page floorplan, refer to these blogs:
Fiori elements – How to Design an Object Page
Fiori elements – How to Develop an Object Page
Result:
The edit page has the line item editable where the property zactive = true.
Also the ‘Delete’ button is enabled when the line item is selected.
But for a different record where property zactive = false, Delete button is not enabled.
Conclusion:
In this blog post, we saw how, by use of annotations, we can make the object page table line items can be made conditionally editable or non-editable. Similarly we can also apply this to conditionally create an associated entity on the object page by adding ‘sap:creatable-path’ annotation to the navigation property. We also observed different annotations for OData v2.0 vs v4.0.
Hi Sumit,
guess this was not BOPF driven and hence the need to tweak the Model. Hopefully this is same as EXTERNAL_CALCULATION variant for the create/update/delete enabled annotations when the CDS is BOPF driven.
Regards,
Sitakant
This looks similar to that but certain things will not work like if we want to do on calculations on fly without saving to the database then it is not possible here, which only only possible with the draft enabled cds.
Hi Mahesh,
Ideally any editable element should be persisted otherwise no point of allowing edit :). For draft capabilities as well I guess we need persistence for draft data which is then converted into core application tables and draft is cleared.
For true on the fly calculations in transient mode elements should be read only and we can resort to virtual elements within CDS definitions.
Regards,
Sitakant.
Yes, EXTERNAL_CALCULATION addition to 'define view' scope is an alternative for BOPF-enabled CDS entities.
Hi Sumit,
I really has a doubt about the enable the inline creation of table entries for apps, I just saw on below wiki that the inline creation only support the draft mode, but I have another strange that I can display and edit the table in the object page facet but when I want to create a entry from list page, the table and the facet disappears, I am wondering if that is also related to draft mode?
Best Regards,
Jay.
Hi Sumit Kumar Kundu ,
thanks for the helpful Blog. How did you suppress the default
when you do
?
I have now both sap:deletable AND sap:deletable-path in the metadata...and this is according eg to https://sapui5.hana.ondemand.com/#/topic/5fe439613f9c4e259015951594c423dc not good....
Thanks,
Wolfgang
Hello Wolfgang,
Sorry about this late response. I didn't have to do anything to make 'sap:deletable' annotaion suppressed. In my case, ABAP standard gateway framework could interpret the annotations well enough to produce the annotation 'sap:deletable-path' where applicable. I tested this with ABAP based OData v2.0. I think in your case, it may be an ABAP version issue (?)
Regards,
Sumit
Hi
Can i use this method for controling the list report table fields?
Or is it restricted to the Object page.
I think, yes you can.
Hi,
How can we define table in object page with more than one record.