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
Request clarification before answering.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Chuma,
Thanks for your help.This question was solved.
JamesG
| User | Count |
|---|---|
| 5 | |
| 4 | |
| 4 | |
| 3 | |
| 2 | |
| 2 | |
| 2 | |
| 2 | |
| 2 | |
| 2 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.