Technology Blogs by Members
Explore a vibrant mix of technical expertise, industry insights, and tech buzz in member blogs covering SAP products, technology, and events. Get in the mix!
cancel
Showing results for 
Search instead for 
Did you mean: 
Ranjith_Kumar
Explorer

In this blog post we going to see the steps to send mail content from Front end UI5 applications to CPI in which we configured the mail adapter for sending the contents to the configured mail id's.

prerequisites for this demo requires:-

  1.  SAP BTP free tier account
  2.  SAP Business Application studio
  3. SAP Integration Suite 

STEPS TO CONFIGURE IFLOW:

  • Create an artifacts with sender , receiver and configure the HTTP adapter as below with the sender, make sure to uncheck the CSRF protection
    MicrosoftTeams-image (5).png

  • We are going to pass JSON payload to this iflow so here we are converting it to xml using  converter based on our requirement.
    MicrosoftTeams-image (8).png
  • Next in the content modifier we going to fetch the mail content from the xml using  predefined xpath functionality, Basically content modifier is used to modify a message by adding additional data to it.
    MicrosoftTeams-image (9).png
  • In the mail adapter we going to pass the property that we created in the content modifier.
    MicrosoftTeams-image (10).png
  • Now we can deploy the iflow once it is deployed we will be getting the generated endpoint which will be used to trigger the iflow
    Screenshot 2024-03-25 221136.png

Configuring the CPI Endpoint in SAP destination service:

Screenshot 2024-03-25 222012.png

CREATION OF SAP UI5 APPLICATION:-
 Now it is time to create application since our requirement is to deploy the application in cloud foundry we are going to use standalone approuter for our development.

1. select the view from the menu and click the command palette.Screenshot (2).png

2. Type route in the popup and select the router generator

Screenshot (3).png

3. Create the router by selecting the standalone router from the drop down and also select the connectivity device then click finishScreenshot 2024-03-25 223912.png

4.Now the mta.yaml with router configuration file is generated by selecting the open folder option from the menu we can open our mailtocpi router like the below.
Screenshot 2024-03-25 224129.png

5. Now Select the New project from template and click the sap fiori application tile.
Screenshot 2024-03-25 224450.png

6.Click start you will be getting the options like the below in that select basic and click next
Screenshot 2024-03-25 224615.png

7. Select none for data source and service selection
Screenshot 2024-03-25 224845.png

8.In the project attributes section make sure to define the path of the router we created it will be and select yes for adding the deployment configuration to the router mta.yaml it will add the ui dependencies in the yaml file.
Screenshot 2024-03-25 225051.png

9.In deployment configuration select cloud foundry and the destination we configured.
Screenshot 2024-03-25 225503.png

10. configure your destination in the xs.app.json under the router folder like the below.

 

{
  "authenticationMethod": "none",
  "routes": [ {

    "source": "/http/sendmail(.*)$",
    "target": "/http/sendmail",
    "destination": "mail",
    "authenticationType": "none",
    "csrfProtection": false
  },
  {
    "source": "^(?:/app|/app/.*)?/resources/(.*)$",
    "target": "/resources/$1",
    "authenticationType": "none",
    "destination": "ui5"
  },
  {
    "source": "^(?:/app|/app/.*)?/test-resources/(.*)$",
    "target": "/test-resources/$1",
    "authenticationType": "none",
    "destination": "ui5"
  }],
  "welcomeFile":"./mailtocpi"
}

 

11.  Adding simple UI with text box and button
Capture11.PNG

12. Inorder to call the endpoint here we using the ajax call for the click event of the button.

 

sap.ui.define([
    "sap/ui/core/mvc/Controller"
],
    /**
     *  {typeof sap.ui.core.mvc.Controller} Controller
     */
    function (Controller) {
        "use strict";

        return Controller.extend("mailtocpi.controller.View1", {
            onInit: function () {

            },
            onSend: function () {

                var text = this.getView().byId("mail").getValue();
                var data = JSON.stringify({
                    "mail": text
                });
                // data.mail = "hi im good"
                $.ajax({
                    type: "POST",
                    url: "/http/sendmail",
                    headers: {
                        "content-Type": "application/json"
                    },
                    data: data,
                    success: function (resultData) {
                        alert("Mail Sent Successfully");
                    }
                });
            }
        });
    });

 

RUN APPLICATION LOCALLY IN BAS:-

In-order to test locally the application in Business application studio we need to configure the path and the destination name in UI5.YAML like the below which will proxy and redirect our request to the destination

Capture12.PNG

select the data source as default from ui5.yaml
Capture13.PNG

Test Result locally:-
Capture14.PNG

Mail is been sent to the configured mail id.
MicrosoftTeams-image (11).png

DEPLOYED APPLICATION IN CLOUD FOUNDRY:-
Once we deploy our application to the cloud foundry space we will be getting the route url running in our space like the below.
tempsnip.png
If we configured the app router correctly by following the above steps you will be getting the api call successfully like the below from your deployed cloud foundry application.

tempsnip.png

CONCLUSION:-

From this blog post we would have got the ideas about  developing the CPI iflow , integration between BTP destination service to CPI , application development and deployment to the cloud fundry.

Labels in this area