cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

CAP Fiori Elements Invoking Custom Action (err: Unknown action import)

buz
Explorer
0 Likes
1,029

Hi CAP experts!

I'm building a Fiori Elements app with a custom action placed in Table toolbar action for the list report, but when I hit the button and inspect the console this error appears:

Uncaught (in promise) Error: Unknown action import

this is the CDS service definition:

service RoyCustDeclMasterDataService {

  function pr_roy_cust_decl_report() returns Boolean;
...

this the JS implementation:

const cds = require('@sap/cds')
const cdsCompile = require('@sap/cds/lib/compile/cds-compile')
module.exports = cds.service.impl(function() {
    this.on('pr_roy_cust_decl_report', async () => {
        try {
            let dbQuery = 'Call "FL_ROY_CUST_DECL_REPORT_SP"( )'
            let result = await cds.run(dbQuery, { })
            cds.log().info(result)
            return true
        } catch (error) {
            cds.log().error(error)
            return false
        }
    })
})

At this point everything is ok, I'm able to launch the function after cds watch with the URL: .../odata/v4/roy-cust-decl-master-data/pr_roy_cust_decl_report()

now I followed this:

https://sapui5.hana.ondemand.com/sdk/#/topic/7619517a92414e27b71f02094bd08d06

and added in manifest.json:

"content": {
                "header": {
                  "actions": {
                    "CustomActions": {
                      "press": "rcd.roycustdeclmdduacus.ext.controller.CustomActions.message",
                      "visible": true,
                      "enabled": true,
                      "text": "Ricalcolo Report"
                    }
                  }
                }
              }

and implement CustomActions.js:

sap.ui.define([
	"sap/m/MessageBox",
	"sap/ui/core/library"
], function(MessageBox, coreLibrary) {
    "use strict";
    return {
		message: async function(oEvent) {
			let sActionName = "pr_roy_cust_decl_report";
			let mParameters = {
				model: this.getModel(),
				label: 'Confirm',	
				invocationGrouping: true	
			};
			this.editFlow.invokeAction(sActionName, mParameters);
		}
    };
});

but when I hit the button and inspect the console this error appears:

Uncaught (in promise) Error: Unknown action import

Any help would be appreciated.

Grazie!

Andrea

Accepted Solutions (1)

Accepted Solutions (1)

Dinu
Active Contributor
0 Likes

In CustomActions.js#8, the action is named incorrectly. You can see the correct way to name these in the sample in Flexible Programming Model Explorer

examples:

.invokeAction("Service.boundAction"

.invokeAction("Service.EntityContainer/unboundAction"
buz
Explorer
0 Likes

Hi Dinu,

this is the metadata:

<EntityContainer Name="EntityContainer">
<EntitySet Name="Comp_Type" EntityType="RoyCustDeclMasterDataService.Comp_Type">
<NavigationPropertyBinding Path="SiblingEntity" Target="Comp_Type"/>
</EntitySet>
<EntitySet Name="RoyCustDecl_IMP_DUACUS001" EntityType="RoyCustDeclMasterDataService.RoyCustDecl_IMP_DUACUS001">
<NavigationPropertyBinding Path="SiblingEntity" Target="RoyCustDecl_IMP_DUACUS001"/>
</EntitySet>
<FunctionImport Name="pr_roy_cust_decl_report" Function="RoyCustDeclMasterDataService.pr_roy_cust_decl_report"/>
</EntityContainer>

I changed the CustomActions.js in this way:

sap.ui.define([
	"sap/m/MessageBox",
	"sap/ui/core/library"
], function(MessageBox, coreLibrary) {
    "use strict";
    return {
		message: function(oEvent) {
			let sActionName = "RoyCustDeclMasterDataService.EntityContainer/pr_roy_cust_decl_report";
			let mParameters = {
				model: this.getModel(),
				label: 'Confirm',	
				invocationGrouping: true,
				requiresNavigation: true,
				isNavigable: true,	
			};
			this.editFlow.invokeAction(sActionName, mParameters);
		}
    };
});

but the error is always the same: "Unknown action import"

Any advice?

Thanks

buz
Explorer
0 Likes
I found the way, instead of "function" I changed to "action" in CDS, now everything is fine!

Answers (0)