Skip to Content
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:

  1. 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.
  2. 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.

 

4 Comments
You must be Logged on to comment or reply to a post.
  • 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.