Skip to Content
0
Feb 08, 2022 at 07:08 AM

Adding action in object page section - CAP/Fiori Elements.

989 Views Last edit Feb 08, 2022 at 07:33 AM 5 rev

Hello,

I am building a CAP based Fiori Elements application for odata v2. I am trying to add a button in one of the form sections in object page. The action in implementation file is not getting triggered and in the console I am getting error.

Schema file

namespace com.report; 
using { Currency, managed, cuid, sap.common.CodeList} from '@sap/cds/common'; 

entity TXReportItem : cuid { 
    reportTitle : String;
    background : String;
    consequence : String;
    Date : Date;
    field1 : String;
    field2 : String;
    field3 : String;
    field4 : String;
    status : String;
    CurrencyCode : Currency;
    virtual visibleEnable : Boolean default true;
}

Service definition

using { com.report as report, sap.common} from '../db/schema'; 
@path : 'ReportService'
service ReportService { 
    annotate ReportItems with @odata.draft.enabled;
    entity ReportItems as projection on report.TXReportItem actions { 
       @sap.applicable.path : 'visibleEnable'
       action calculateValues();
    };  }

UI Annotation

FieldGroup #ReportSection : {Data : [ 
    { $Type : 'UI.DataFieldForAction', Action : 'ReportService.EntityContainer/ReportItems_calculateValues',          Label : 'Calculate', }, 
    {Value : reportTitle},
    {Value : background},
    {Value : consequence},
    {Value : status},
    {Value : CurrencyCode}
]},

Service implementation

const cds = require("@sap/cds");

module.exports = cds.service.impl(async function () {
   this.on("calculateValues", async (req) => { 
      console.log("inside calculateValues"); 
    });
}

Error in console

Uncaught (in promise) Unknown Function Import undefined

Please let me know what I am missing or where I am going wrong.

Thank you,

Navya