Skip to Content
0
Jan 23, 2023 at 03:54 PM

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

244 Views Last edit Jan 23, 2023 at 04:07 PM 6 rev

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.

worklist-selection.png

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.

require.png

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

module.png

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 <3

Attachments

require.png (101.9 kB)
module.png (108.9 kB)