Skip to Content

Problem calling function in javascript

Hi,

This is basic but I am new to javascript so appreciate any help.


My controller, View1.controller.js., has two functions. onSLConnect is being called from a button press and is working correcty.


However, the call to onConnectSuccess does not seem to execute. The label text does change.

Is it possible to call functions that are in the same javascript file? Is there something I need to do to enable that?

Or do I need to put the called function in its own file?


onConnectSuccess(thisView) {

var oLabel1 = thisView.byId("Label1");

oLabel1.setText("Success");

},




onSLConnect: function() {

var thisView = this.getView();

.........

this.onConnectSuccess(thisView);

}

Thanks,

Mel

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

3 Answers

  • Best Answer
    Apr 09 at 07:28 PM

    The problem was that the function I created was part of the controller and not the view.

    I was trying to call the code from inside a "press" event so the function had to be referenced explicitly to the controller:

    The function was created in the ...controller.js

    onLoginSuccess : function(thisView){.......}

    As was the calling function - which fails.

    onSLConnect: function() {

    //.............(code that works)

    var thisView = this.getView();

    this.onLoginSuccess(thisView); ---Fails


    Answer:

    var thisView = this.getView();

    var oController = sap.ui.controller("MyAppMyApp.controller.View1"); ---the reference is in the first line of the ....controller.js
    oController.onLoginSuccess(thisView);

    Add comment
    10|10000 characters needed characters exceeded

  • Apr 05 at 10:22 PM

    are you using js view?

    Add comment
    10|10000 characters needed characters exceeded

    • Hi Jun,

      I am using an xml view with a js controller. Is that what you mean?

      The controller exposes functions such as my

      onSLConnect. This executes when the button is pressed.

      Now I would like to call my other function

      this.onConnectSuccess which is in the same js controller file.

      There are no errors but the code does not seem to run.

  • Apr 06 at 12:51 AM


    onConnectSuccess:function(thisView) {

    var oLabel1 = thisView.byId("Label1");

    oLabel1.setText("Success");

    },

    Add comment
    10|10000 characters needed characters exceeded