user29582969
user29582969

Reputation: 1

SAP CAP update send

I am currently working my way into SAP Cap.

Now I have written a test ui5 page and would like to send an update to the cds service after pressing a button, via Postman this is no problem but in the ui5 controller I just can't get it to work. I have already tried 5 different ways. can someone please help me with a short explanation would be good thanks. My setup:

Backend: SAP CAP (Node.js) Frontend: SAP Fiori with SAPUI5 (XML view) Model: OData V4 (generated by CAP)

Current code

buttonTimeEnd: async function () {
            const oAccount = this.getView().getModel("oAccountData");
            const oToLoggedProductionOrderOperation = this.getView().getModel("oToLoggedProductionOrderOperation");

            const vView = this.getView();
            const vAccountPage_ToolboxSection = vView.byId("AccountPage_ToolboxSection");
            const vAccountPage_CurrentOrdersSection = vView.byId("AccountPage_CurrentOrdersSection");

            if (!oAccount || !oToLoggedProductionOrderOperation) {
                MessageBox.error(this.getResourceBundle().getText("errorLoadingBackgroundData"));
                return;
            }

            const oToLoggedProductionOrderOperationData = oToLoggedProductionOrderOperation.getData();

            if (oToLoggedProductionOrderOperationData.controlStatus === 'logged') {
                try {
                    const oModel = this.getView().getModel("modelAccount");
                    const oOperation = oModel.bindContext("/UpdateLogProductionOrderOperation(...)");
                    
                    oOperation.setParameter("UUID", oToLoggedProductionOrderOperationData.UUID);
                    oOperation.setParameter("controlStatus", "waitingSend");

                    await oOperation.execute().then(() => {
                        MessageToast.show(this.getResourceBundle().getText("timeRecordingSuccessful"));
                        
                        // Aktualisiere die lokale Ansicht
                        oToLoggedProductionOrderOperation.setProperty("/controlStatus", "waitingSend");
                        
                        // Sektionen aktualisieren
                        if (vAccountPage_CurrentOrdersSection) vAccountPage_CurrentOrdersSection.setVisible(false);
                        if (vAccountPage_ToolboxSection) vAccountPage_ToolboxSection.setVisible(true);
                    }).catch((oError) => {
                        MessageBox.error(this.getResourceBundle().getText("errorTimeRecording"));
                        console.error("Execute Error:", oError);
                    });

                } catch (oError) {
                    MessageBox.error(this.getResourceBundle().getText("errorTimeRecording"));
                    console.error("Catch Error:", oError);
                }
            }
        },

I have already tried it with oModel.update oModel.oBindList

Upvotes: 0

Views: 46

Answers (0)

Related Questions