cancel
Showing results for 
Search instead for 
Did you mean: 

SAP public cloud app get selection row

09-08-2025 9:11 PM
JamesG Participant
2231 views 5 comments Go to solution
0 Likes
SAP Managed Tags
Labels
SAP RAP
Subscribe

Hi experts,

I added a button to the List Report generated by RAP using the BAS Development Guide. How can I get the selected row data?

I added a button to the Object generated by RAP using the BAS Development Guide. How can I get the selected row data?

 

 

Thanks advance

0 Likes

Accepted Solutions (1)

Accepted Solutions (1)

Chuma
Active Contributor
0 Likes

Hello @JamesG 

Thank you for reaching out to the SAP Community and your questions

Here are the two clean patterns for SAP S/4HANA Public Cloud Edition (Fiori elements, OData V4):

List Report (table selection)

onCustomAction: function () {

  const extApi = this.base.getExtensionAPI();

  const ctxs = extApi.getSelectedContexts();           // v4 Context[]

  if (!ctxs.length) { sap.m.MessageBox.warning("Select a row first."); return; }

  const rowData = ctxs[0].getObject();                 // plain JS object

  // ...use rowData (or ctxs.map(c => c.getObject()) for multi-select)

}

Object Page

onCustomOPAction: function () {

  const ctx = this.base.getExtensionAPI().getBindingContext();

  if (!ctx) { return; }

  const obj = ctx.getObject();                         // header data

}

 

If you require rows from a specific sub-table on the Object Page:

const selected = this.base.getExtensionAPI().getSelectedContexts("MyStableTableID");

const firstRow = selected[0]?.getObject();

Check below SAP references

SAPUI5 Demo Kit  sap.fe.core.ExtensionAPI (OData V4): API offering getSelectedContexts() and getBindingContext() methods for List Report and Object Page controllers’ extensions. SAPUI5 SDK-Discover New Enterprise Grade Horizons

SAP Help Portal Using the extension API (Fiori elements V4): When and where to utilise the Extension API in controller extensions. SAP Help Portal-Using the extension API

Let me know if you need further information

Best regards,
Chuma

JamesG
Participant
0 Likes

Hi Chuma,
Thanks for your response.This is my code:

sap.ui.define([
    "sap/m/MessageToast",
    "sap/m/MessageBox"
], function (MessageToast, MessageBox) {
    'use strict';

    return  {
        onAfterRendering: function () {
            this._ext =  this.base.getExtensionAPI();
        },
        Print: function (oEvent) {
            // const extApi = this.base.getExtensionAPI();
             const ctxs = this._ext.getSelectedContexts(); 
             if (!ctxs.length) { sap.m.MessageBox.warning("Select a row first."); return; }   
             const rowData = ctxs[0].getObject(); 
             console.log(rowData);
        }
    };
});

 I reached this point by running the code: const ctxs = this._ext.getSelectedContexts(); At that time, an error occurred: "Cannot read properties of undefined (reading 'getSelectedContexts')".
How should I handle this situation?
Best Regards

Answers (1)

Answers (1)

Chuma
Active Contributor
0 Likes

Hello @JamesG 

Please check your private message.

With kind regards

Chuma

JamesG
Participant

Hi Chuma,
Thanks for your help.This question was solved.

 


JamesG