cancel
Showing results for 
Search instead for 
Did you mean: 

Setting Default Values for Create in ABAP RESTful application development

kchatch1
Explorer
3,240

Hello,

Using the ABAP RESTful approach (https://help.sap.com/docs/abap-cloud/abap-rap/abap-restful-application-programming-model) I have implemented an app using root entity CDS view, metadata extension, behavior definition, service definition, and service binding.  

Everything works fine, but I am unable to figure out how to implement DEFAULT values for fields when I click the CREATE button.  I have a local helper class that is handling auto numbering just fine (using class for getting a GUID) and it also populates values for fields ON CREATE execution using a determination.  But I also need DEFAULT values populated when I INITIALLY click CREATE.  

The approach of using "action" does not work ... it does not populate any values initially.  

 

Please provide the behavior definition entry as well as the class ABAP code for defaulting values. 

Thanks,

Kevin 

Accepted Solutions (1)

Accepted Solutions (1)

JessieCheah
Product and Topic Expert
Product and Topic Expert
0 Kudos

Hi Kevin,

if you are working on BTP ABAP Environment release 2311, you can use default values function to set default values for create, CBA, action and functions. Please refer to https://help.sap.com/docs/abap-cloud/abap-rap/operation-defaulting , there is also an example linked at the bottom of the page.

SAP S/4HANA Cloud, public edition will get this feature soon but OnPrem will take longer.

Regards,
Jessie

Archish
Newcomer
0 Kudos

OnPrem will be 2025 release? or there is a hope with any upcoming 2023 feature packs?

 

Regards,

Archish

TiagoAlmeida
Participant
Hi, Thanks for sharing. What is the solution for onprem on lower versions ? When trying to use this feature we get an error ' "association create / default function" is not supported in this ABAP release. ' . This feels like such a basic requirement. Is there any alternative to default values of a child entity? Thank you in advance

Answers (1)

Answers (1)

klbi
Explorer
0 Kudos

For anyone else landing in here, in hopes of finding the answer to how you can add initial/default values to your entity (f.ex. for hiding fields, or defaulting types, etc) - currently there's no way to achieve this on-prem, in an unmanaged scenario, in your behavior pool class - or in metadata on your cds views...

The only way I could find, to achieve this requirement - was to add a controller extension to your Fiori Elements app / object page, and adding something along the lines of the following snipplet of code to it:

 

        onInit: function() {
            this.extensionAPI.attachPageDataLoaded($.proxy(this.onPageLoaded, this)); 
        },

        onPageLoaded: function(oEvent){
            if(this.getView().getModel("ui").getProperty("/createMode")) {
                var ctx = this.getView().getBindingContext();
                ctx.getModel().setProperty(ctx.getPath() + "/<Property>", <value>);
            }
        }

 

 

Claudia_D
Discoverer
0 Kudos
I have on-prem with managed scenario. Can I use your code snipplet?
Claudia_D
Discoverer
0 Kudos
I use Visual Studio Code. Where I have to insert the code snipplet? In which file?
klbi
Explorer
0 Kudos

@Claudia_D , first you need to declare a controller extension; like so - in manifest.json:

 

"sap.ui5": {
  "extends": {
    "extensions": {
      "sap.ui.controllerExtensions": {
        "sap.suite.ui.generic.template.ObjectPage.view.Details": {
          "controllerName": "mycomponent.ext.controller.MyEntityExt" 

 

 

Then you create a new file, MyEntityExt.controller.js in the ext/controller folder of your project, and give it the following contents:

 

sap.ui.define([
	"sap/suite/ui/generic/template/extensionAPI/extensionAPI"
], function( extensionAPI ) {
	"use strict";
    return sap.ui.controller("mycomponent.ext.controller.MyEntityExt", {
        onInit: function() {
            this.extensionAPI.attachPageDataLoaded($.proxy(this.onPageLoaded, this)); 
        },
        onPageLoaded: function(oEvent){
.... as I wrote earlier.