cancel
Showing results for 
Search instead for 
Did you mean: 

Fiori - Call NodeJS function from Fiori Controller (Import / require not working)

raizon
Explorer
0 Kudos

Hello dear Community I need your help / advice

I have a Fiori Freestyle worklist App displaying a custom cds view in which I select mutiple entries and want to send the objects to my NodeJS Backend(FioriObj.js) in which the objects get combined and send to the mapping (mapping.js) function.

The Problem is: How do I properly import a normal NodeJS file in a UI5 Controller?

sap.ui.define([
    'sap/m/MessageToast',
    "./BaseController",
    "sap/ui/model/json/JSONModel",
    "../model/formatter",
    "sap/ui/model/Filter",
    "sap/ui/model/FilterOperator",
    "app/srv/FioriObj" <=== Path to class that needs to be accessed by the controller

], function (MessageToast,
    BaseController,
    JSONModel,
    formatter,
    Filter,
    FilterOperator,
    FioriObj) {
    "use strict";

 
    return BaseController.extend("app.controller.Worklist", {
     .....

      

        onUpdateSend: async function() {
            var aSelectedProducts, i, sPath, oProductObject;
            let messageArray = [];
            aSelectedProducts = this.byId("table").getSelectedItems();
            console.log(aSelectedProducts)
            if (aSelectedProducts.length) {
                for (i = 0; i < aSelectedProducts.length; i++) {
                    sPath = aSelectedProducts[i].getBindingContext().getPath();
                    oProductObject = aSelectedProducts[i].getBindingContext().getObject();
                    console.log(oProductObject);
                    messageArray.push(oProductObject.Supplier +" PO: "+ oProductObject.PurchaseOrder) 
                }
                MessageToast.show("Selected: " + messageArray);
                console.log("Message Toast log:" + messageArray)
                let Send = await FioriObj.ObjectReceiver(oProductObject);  <====== object that needs to be sent to a class outside of the controller
} else { console.log("Error") } } }); },true); <br>


As shown in the picture, the given file gets found but despite not showing any errors in BAS, Chrome Console gives me errors for using import / require statements for the mapping.js as well as module.exorts.

Same for just the module.exports without any require / import:

Is there a way to send an object to your local backend and keep using regular NodeJs in that class / what do I need to change?

Thanks in advance for your advice & help ❤️

Accepted Solutions (1)

Accepted Solutions (1)

gregorw
Active Contributor

I would suggest you implement your backed using SAP Cloud Application Programming Model and then consume it via an OData Service call. Backend and Frontend can share JS libraries, but the communication must happen via HTTP(S).

raizon
Explorer
0 Kudos

Much appreciated! Is there a GitHub project / sample in which this Frontend => Backend Communication is showcased?

gregorw
Active Contributor

I would suggest the learning journey: Develop Applications Running on SAP BTP Using SAP HANA Cloud to get a more solid understanding.

Answers (1)

Answers (1)

junwu
Active Contributor

they are all js, but they live in different world, you cannot do that.