Skip to Content
author's profile photo Former Member
Former Member

How to call a function in a controller from different function which is in same controller


In a controller , I have two function 'A' and 'B' , how can we call function 'B' from function 'A'. The normal JS approach is not working for me.

Sample code:

sap.ui.controller("trailbindingtile.myexample", {

A: function(oEvent){

alert("in A");

B(); // this is not invoking function B. I also tried "sap.ui.getCore().getControl("tileexample").myexample().B()"


B: function(){

alert ("in B");



Kindly let me know the actual way of implementing this?


Buddha Puneeth N.

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

3 Answers

  • Best Answer
    Posted on Jan 06, 2014 at 12:15 PM

    Hi Nandanoor,

    You can use below one...

    A: function(oEvent){



    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Jan 06, 2014 at 12:17 PM

    Hi Buddha

    Start reading code.



    John P

    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Jan 06, 2014 at 12:31 PM

    The issue you have is context. A common UI5 pattern is to explicitly provide the context for the event handler when attaching it, and that context is the controller (here, your parent of A and B).

    So if in your view you have something like this:

    oButton.attachPress(oController.A, oController);

    then the context that A will have in "this" is enough to allow you to then write:

    alert("in A");


    and B will get invoked.

    If you're using XML views, then this context is passed automatically; you don't need to specify it explicitly. Like this:

    <Button text="..." press="A" />


    Add a comment
    10|10000 characters needed characters exceeded

    • Hi

      Please help us to help you, by creating a Gist with all the relevant files that you have. It's a lot easier for us to reproduce your problem on our local machines, or just browser the entire set of source code files, if it's in a Gist. Much easier than downloading ZIP files containing text files, that we then have to figure out how to put together and make into a complete runnable and debuggable app.

      When you do create the Gist, please also include the other files (in this case not just the view and controller, but also the index.html or equivalent).

      Create a Gist here: Gists

      (although it's not related to SAPUI5, here is an example of a Gist with multiple files: )

      UPDATE 09 Jan 2014: See Help Us To Help You - Share Your Code

      Kind regards


Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.