Introduction
Based on my brief experience with SAP Fiori Elements, I have previously written two blogs as follows:
This blog post serves as a follow-up to the following preceding post:
CAP with Fiori Elements: Actions on List Report / Object Page using Annotations – Part1
Within this blog post, I have outlined my observations regarding the various types of actions achievable through service definition and annotations.
Explanatio of POC Scenario and Its Resources
We will use the sample project “cap-fe-lr-op-actions” that I have shared on GitHub here to explain the concepts. Let’s briefly examine the project and some of its essential files.
Project Structure | Folder or File |
|
Service “cap_fe_lr_op_actions_service” proivides following data set: Roots, Items, Categories, Criticalities, Samples.
Please be aware that in this blog post, my emphasis is on illustrating the functionality of presenting tables in various configurations. It’s worth noting that the service utilized for demonstration purposes may not be flawless and is solely used to explain the functionalities.
Detailed Explanation
Now, let's explore various types of actions that can be incorporated through annotations. To illustrate, we'll use the Samples view from the list report within the application (marked above).
1. Critical Action
annotate service.sua_action_critical with @Common.IsActionCritical; annotate service.Samples actions { sba_action_critical @Common.IsActionCritical; };
2. Action with Dialog having Text Input
type inText : { comment: String; }; entity Samples as projection on db.Samples actions { action sba_action_text(text:inText:comment); };
annotate service.inText:comment with @Common.Label :'MultiLine Input Text';
annotate service.inText:comment with @UI.MultiLineText:true;
3. Action with Multiple Input
/*=======>> Action Definition <<=======*/ type inComplexObject : { comment : String(50); date : Date; datetime: DateTime; confirm : Boolean; value : Integer; }; action sba_action_complex( aprcomment :inComplexObject:comment, aprdate :inComplexObject:date, aprdatetime :inComplexObject:datetime, aprconfirm :inComplexObject:confirm );
/*==========>> Annotations <<==========*/ annotate service.inComplexObject { comment @Common.Label: 'Comment'; date @Common.Label: 'Date of Approval'; datetime @Common.Label: 'Time of Processing'; confirm @Common.Label: 'Confirmation'; };
Above action definition and annotations will provide following result:
4. Action with Mandatory and Default Input
/*=======>> Action Definition <<=======*/ type inOtherObject: { input1 :String(50); input2 :String(50); input3 :String(50); }; @cds.odata.bindingparameter.name : '_it' action sba_action_other( text1 :inOtherObject:input1, @UI.ParameterDefaultValue:'default text' text2 :inOtherObject:input2, @UI.ParameterDefaultValue: _it.name text3 :inOtherObject:input3 );
/*==========>> Annotations <<==========*/ annotate service.inOtherObject { input1 @Common.Label: 'First Input' @mandatory; input2 @Common.Label: 'Second Input'; input3 @Common.Label: 'Third Input'; };
5. Action with DefaultValueFunction based Input
/*=======>> Action Definition <<=======*/ service cap_fe_lr_op_actions_service { type inObjectFn:{ text1: String; text2: String; } @Common.DefaultValuesFunction: 'cap_fe_lr_op_actions_service.getDefaults' action sba_action_defaultfn(text1:inObjectFn:text1, @@UI.ParameterDefaultValue: 'default value' text2: inObjectFn:text2); function getDefaults() returns inObjectFn; } /*=======>> Defulat Function <<=======*/ srv.on(["getDefaults"], async (req) => { return { text1: 'default text 01', text2: 'default text 02' }; });
/*==========>> Annotations <<==========*/ annotate service.inObjectFn { text1 @Common.Label: 'First Text Input'; text2 @Common.Label: 'Second Text Input'; }
Result:
6. Action with Value Help Input
/*=======>> Action Definition <<=======*/ type inObject :{ category : String; criticality : String; } action sba_action_valuehelp( category:inObject:category, criticality:inObject:criticality );
/*==========>> Annotations <<==========*/ annotate service.inObject { category @( Common.Label: 'Sample Category', Common.ValueList : { $Type : 'Common.ValueListType', CollectionPath : 'Categories', Parameters : [ { $Type : 'Common.ValueListParameterInOut', LocalDataProperty : category, ValueListProperty : 'id' }, { $Type : 'Common.ValueListParameterDisplayOnly', ValueListProperty : 'descr' } ], Label : 'Choose One Category' }, Common.ValueListWithFixedValues : false ); criticality @( Common.Label: 'Sample Criticality', Common.ValueList : { $Type : 'Common.ValueListType', CollectionPath : 'Criticalities', Parameters : [ { $Type : 'Common.ValueListParameterInOut', LocalDataProperty : criticality, ValueListProperty : 'id' }, { $Type : 'Common.ValueListParameterDisplayOnly', ValueListProperty : 'descr' } ], Label : 'Choose One Criticality' }, Common.ValueListWithFixedValues : true ); };
Miscellanous features
1. Handling Messages
req.notify('message to be shown on message toast'); req.error('erroneous message shown on message dialog')
srv.on("msg_trigger",async (req) => { req._.odataRes.setHeader('sap-messages', JSON.stringify([ { "code" : "500", "message" : "info: messages trigger action called!", "numericSeverity" : 2 }, { "code" : "504", "message" : "This can only be triggered for draft data", "numericSeverity" : 3 }, { "code" : "504", "message" : "Error happened! Contact your IT Admin", "numericSeverity" : 4 } ])); });
This results in following message dialog:
2. Criticality for Actions
Conclusion
In this blog post, we have delved into different kinds of actions generated based on service definition and annotations along with handling messages on SAP Fiori Elements.
Together, the Cloud Application Programming Model and Fiori Elements improve developer experience while also boosting productivity and accelerating the development of enterprise-ready applications.
More information about Fiori Elements with cloud application programming model can be found here. You can follow my profile to get notification of the next blog post on CAP or Fiori Elements. Please feel free to provide any feedback you have in the comments section below and ask your questions about the topic in sap community using this link.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
27 | |
26 | |
14 | |
13 | |
13 | |
12 | |
10 | |
7 | |
7 | |
6 |