Dynamic Overview Page cards with mandatory filter

Working with Fiori Elements Overview Pages is challenging because of the dynamicity of the data, at the same time this is a very interesting resource to deliver to customer as they can analyze several data in different ways. On this blog post I going to explain how we make each individual card consider filters of fields not exposed on the card and at the same time consider that a field could be not filtered, showing all results provided from that.

Steps needed:

  1. Mandatory parameter with default value other than Environment fields;
  2. Initial value added to Fiori Elements Value Help to be considered as default;
  3. Query considering the default value as a value that won’t filter the field and bring all results and also prepared to apply a specific value on the filter.
  1. Mandatory parameter with default value other than Environment fields;

When researching about mandatory or not mandatory parameters on blogs the only thing I found was the following options:

  • In order to the filter not be mandatory apply filter annotation on the field, but that was not an option on my case because as I was dealing with ovp cards and each card has its on group by, not all the fields required was available on CDS, so parameters was really necessary;
  • Parameters on CDS make filters mandatories, and its possible to send standard values in case you are dealing with a date or client field, for example:
define view entity C_YourCdsViewName with parameters @Environment.systemField: #SYSTEM_DATE P_ValidFromDateTime :yourdataelement, @Environment.systemField: #USER P_CreatedByUser :yourdataelement

and so on, you can find more options searching on Help Portal by @Environment CDS Annotations.

However, sometimes its necessary to pass another kind of fields (not environment fields) as default value. This is easy to do by CDS or by ui5 as follow:

define view entity C_YourGlobalFilterCDS with parameters @Consumption.defaultValue: '00' @Consumption.valueHelpDefinition: [ { entity: { name: 'I_CDSValueHelp', element: 'DistributionChannel' } } ] P_DistributionChannel :yourdataelement @Consumption.defaultValue: '000000000000' @Consumption.valueHelpDefinition: [ { entity: { name: 'I_CDSValueHelp', element: 'CreatedByUser' } } ] P_CreatedByUser :yourdataelement
 modifyStartupExtension: function (oCustomSelectionVariant) { sap.ui.getCore().byId("begginingOfYourFilterId--ovpGlobalFilter-filterItemControlA_-_Parameter.P_DistributionChannel").setSelectedKey("00"); },

2. Initial value added to Fiori Elements Value Help to be considered as default;

As you are using mandatory field combined with a Value Help, the default value won’t be recognized as a valid entry and Fiori Elements won’t trigger the http request in order to create the ovp cards, or whatever you need to get created.

A suitable solution we found on this case was to redefine getentityset method of the value help and add a “Select All” option on this list as follow:

 METHOD i_cdsvaluehelp_get_entityset. if_sadl_gw_dpc_util~get_dpc( )->get_entityset( EXPORTING io_tech_request_context = io_tech_request_context IMPORTING et_data = et_entityset es_response_context = es_response_context ). INSERT VALUE #( distributionchannel = “00” distributionchannelname = “-Select All-“ ) INTO et_entityset INDEX 1. ENDMETHOD.

With the default value set on CDS or on startup of ui5, the page is automatically loaded with this option of the value help selected, and then Fiori elements can do the requests successfully.

3. Query considering the default value as a value that won’t filter the field and bring all results and also prepared to apply a specific value on the filter.

Also, in order to get the query correctly, we need to set a where condition as follow.

define view entity C_YourCardCds with parameters P_DistributionChannel :yourdataelement, P_CreatedByUser :yourdataelement
as select from I_CDSWichContainsAllData
{ key DistributionChannel, @UI: { dataPoint: {title: 'Channel', visualization: #BULLET_CHART}, lineItem: [{position: 10, label: 'Channel', qualifier: 'Q2'}] } DistributionChannelName, avg(WorkDuration as abap.decfloat16) as WorkDuration
}
where CreatedByUser = case when $parameters.P_CreatedByUser = '000000000000' then CreatedByUser else $parameters.P_CreatedByUser end and DistributionChannel = case when $parameters.P_DistributionChannel = '00' then DistributionChannel else $parameters.P_DistributionChannel end
group by DistributionChannel, DistributionChannelName

Notice that on this example, CreatedByUser field is not contained on the CDS card, however, this information is necessary in order to change the card according to the filter. If none CreatedByUser was selected, all Distribution Channel should be shown, but if a CreatedByUser was selected for an specific data, just DistributionChannel of this person should be shown, plus the Work Duration always being recalculated accordingly. In other words, if the parameter is “00”, the all data should be retrieved, otherwise the selected line will be considered as filter for the query.

On this blog I shared with you a solution for providing dynamicity for cards on overview page, and it’s also important to mention that parts of this syntax (cases on where clause) is not accepted on SAP Deliveries previous to OP2021. In such cases, I recommend to not use parameter, but simple Consumption Filter and provide the dynamicity by js/ui5 resources combined with Fiori Elements. This blog post is also useful if you need to deal with mandatory parameters for other floorplans as List Reports, for example. Besides that, also possible to take advantage of the customization made within the value help.

I hope you have enjoyed this content, please feel free to provide feedback, suggestions and make questions on comment’s section. Follow my profile for Fiori development content.