Skip to Content

SAP Web IDE Hybrid Application Toolkit Introduction and Demo


Video Link


Here is the code needed to add the button for adding barcode reader to the searchfield (time 14:10)


Master.view.xml:

<contentRight>

     <Button id=”barcodeButton” icon=”sap-icon://bar-code” tooltip=”Bar Code Scanner” press=”onBarCodeScan”></Button>

</contentRight>

Master.controller.js

onBarCodeScan: function() {

     var that = this;

     var code = “”;

if (!cordova.plugins.barcodeScanner) {

     sap.m.MessageBox.show(“barCode scanning not supported”, sap.m.MessageBox.Icon.INFORMATION, “Bsrcode scanning”);

     return;

}

cordova.plugins.barcodeScanner.scan(

          function (result) {

                code = result.text;

                that.getView().byId(“searchField”).setValue(code);

                that.onSearch();

          },

          function (error) {

           alert(“Scanning failed: ” + error);

          }

     );

},

Here is the code needed to add the button for adding the contact to mobile device (time 5:00)

Detail.view.xml:

<Button xmlns=”sap.m” text=”add to contact” press=”addContact”></Button>

Detail.controller.js:

jQuery.sap.require(“sap.m.MessageBox”);

      addContact: function(oEvent) {

           if (!navigator.contacts) {

                sap.m.MessageBox.show(“Contacts API only supported on Devices/Simulators”, sap.m.MessageBox.Icon.INFORMATION, “Add Contact”);

                return;

           }

           var oView = this.getView();

           var sEntityPath = “/” + oEvent.getSource().getBindingContext().getPath().slice(1) + “/SupplierDetails”;

           var bpData = oView.getModel().getData(sEntityPath);

           //Get Contacts data

           var name = bpData.SupplierName;

           var phone = bpData.PhoneNumber;

           var email = bpData.EmailAddress;

           var contact = navigator.contacts.create();

           contact.name = { givenName: name };

           var phoneNumbers = [];

           var emails = [];

   

           phoneNumbers[0] = new ContactField(“work”, phone, true);

           emails[0] = new ContactField(“email”, email, false);

           contact.phoneNumbers = phoneNumbers;

           contact.emails = emails;

           contact.save();

           sap.m.MessageBox.show(“Successfully saved into Device Contacts “, sap.m.MessageBox.Icon.SUCCESS, “Add Contact”);

     },

To report this post you need to login first.

2 Comments

You must be Logged on to comment or reply to a post.

  1. Ram Kumar Karunamurthy

    Dear Jennifer,

    Thank you for share this excellent post. This post really helps me lot. After creating the application in Web IDE working fine on browser and Bar code has been working fine.

    I was deployed in this application into SAPUI5 ABAP Repository(BSP File). After that I was executed this application from BSP file. Master and Detail screen values are loaded successfully. When I was clicked the Bar code scan button not opening the camera. I am getting the error message as “Uncaught ReferenceError: cordova is not defined” in console.

    Kindly give me any suggestion to resolve this issue.

    Regards,

    Ram

    (0) 

Leave a Reply