# currentcontroller differs from application.getActiveWindow()

**URL:** <https://forum.servoy.com/t/currentcontroller-differs-from-application-getactivewindow/18105>\
**Category:** Classic Servoy\
**Created:** [August 7, 2014, 7:10am UTC](https://forum.servoy.com/t/currentcontroller-differs-from-application-getactivewindow/18105 "2014-08-07T07:10:52Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![maria.kyselova](https://avatars.discourse-cdn.com/v4/letter/m/82dd89/32.png) [@maria.kyselova](https://forum.servoy.com/u/maria.kyselova)\
**Post date:** [August 7, 2014, 7:10am UTC](https://forum.servoy.com/t/currentcontroller-differs-from-application-getactivewindow/18105/1 "2014-08-07T07:10:52Z")

</div>

Hi guys,

application.getActiveWindow().controller.getName() returns a different name than currentcontroller.getName().  
I assume this is not normal?

My function starts running in a window that opens another window, something like that:

function doWhatever() {

doSomethingInCurrentWindow();  
openNewWindow();  
forms[currentcontroller.getName()].doSomethingInNewWindow();  
}

This works beautifully.  
As soon as I replaced currentcontroller.getName() with application.getActiveWindow().controller.getName(), my last line is executed in the current window, not the new one.

Sample solution attached: click on the button to open a new window; upon opening a new window it will set the label text in the new window with the help of both currentcontroller and application.getActiveWindow(). The latter will set the label in the old window, the former - in the new.

This means those two are not interchangeable. We rely a lot on the currentcontroller in are existing solutions. Please advise how to deal with this and whether it’s a bug.

[currentController.servoy](https://forum.servoy.com/uploads/short-url/AgQkPA57U4KnA77tyvOXWUtFP8z.servoy) (3.82 KB)

---

<div class="post-metadata">

**Author:** ![ROCLASI](https://yyz2.discourse-cdn.com/flex010/user_avatar/forum.servoy.com/roclasi/32/4371_2.png) [@ROCLASI](https://forum.servoy.com/u/ROCLASI)\
**Post date:** [August 12, 2014, 7:01am UTC](https://forum.servoy.com/t/currentcontroller-differs-from-application-getactivewindow/18105/2 "2014-08-12T07:01:55Z")

</div>

Hi Maria,

If you haven’t already I suggest you file this issue in the [bug tracker](http://support.servoy.com). It sure looks like a bug to me.

---

<div class="post-metadata">

**Author:** ![maria.kyselova](https://avatars.discourse-cdn.com/v4/letter/m/82dd89/32.png) [@maria.kyselova](https://forum.servoy.com/u/maria.kyselova)\
**Post date:** [August 13, 2014, 11:22pm UTC](https://forum.servoy.com/t/currentcontroller-differs-from-application-getactivewindow/18105/3 "2014-08-13T23:22:42Z")

</div>

[Done](https://support.servoy.com/browse/SVY-7049). Thanks.

---

<div class="post-metadata">

**Author:** ![ROCLASI](https://yyz2.discourse-cdn.com/flex010/user_avatar/forum.servoy.com/roclasi/32/4371_2.png) [@ROCLASI](https://forum.servoy.com/u/ROCLASI)\
**Post date:** [August 14, 2014, 12:57am UTC](https://forum.servoy.com/t/currentcontroller-differs-from-application-getactivewindow/18105/4 "2014-08-14T00:57:58Z")

</div>

Added my vote to the [issue](https://support.servoy.com/browse/SVY-7049).

---

<div class="post-metadata">

**Author:** ![maria.kyselova](https://avatars.discourse-cdn.com/v4/letter/m/82dd89/32.png) [@maria.kyselova](https://forum.servoy.com/u/maria.kyselova)\
**Post date:** [August 18, 2014, 12:34am UTC](https://forum.servoy.com/t/currentcontroller-differs-from-application-getactivewindow/18105/5 "2014-08-18T00:34:09Z")

</div>

> ROCLASI:  
> Added my vote to the [issue](https://support.servoy.com/browse/SVY-7049).

Thanks Rob.  
Did you have a look at Johan’s and my comments in the case? Are we missing each other’s point?

---

<div class="post-metadata">

**Author:** ![ROCLASI](https://yyz2.discourse-cdn.com/flex010/user_avatar/forum.servoy.com/roclasi/32/4371_2.png) [@ROCLASI](https://forum.servoy.com/u/ROCLASI)\
**Post date:** [August 18, 2014, 7:32am UTC](https://forum.servoy.com/t/currentcontroller-differs-from-application-getactivewindow/18105/6 "2014-08-18T07:32:02Z")

</div>

Hi Maria,

I added a comment to the issue.

It seems the order of events have changed when you create and open a new window and in that same method try to do things on the (new) active window.  
At that point the new window is not active yet so getActiveWindow will return the old window (which is different behavior than when you used currentcontroller). So the trick is to call it after the method is done by putting the rest of your code in another method and deferring that method call by way of the scheduler plugin:

```auto
plugins.scheduler.addJob('DEFERRED', new Date(), myDeferredMethod); 

```

This will trigger the method _right_ after the current method is done.

Maybe I missed it but I can’t find no documentation of this behavior change in the release notes nor the wiki.

Hope this helps.

---

<div class="post-metadata">

**Author:** ![maria.kyselova](https://avatars.discourse-cdn.com/v4/letter/m/82dd89/32.png) [@maria.kyselova](https://forum.servoy.com/u/maria.kyselova)\
**Post date:** [August 22, 2014, 3:09am UTC](https://forum.servoy.com/t/currentcontroller-differs-from-application-getactivewindow/18105/7 "2014-08-22T03:09:05Z")

</div>

> ROCLASI:  
> Hi Maria,
> 
> I added a comment to the issue.
> 
> It seems the order of events have changed when you create and open a new window and in that same method try to do things on the (new) active window.  
> At that point the new window is not active yet so getActiveWindow will return the old window (which is different behavior than when you used currentcontroller). So the trick is to call it after the method is done by putting the rest of your code in another method and deferring that method call by way of the scheduler plugin:
> 
> ```auto
> plugins.scheduler.addJob('DEFERRED', new Date(), myDeferredMethod); 
> 
> ```
> 
> This will trigger the method _right_ after the current method is done.
> 
> Maybe I missed it but I can’t find no documentation of this behavior change in the release notes nor the wiki.
> 
> Hope this helps.

Thanks Robert.  
I was trying to avoid using the schedulers, we’ve got a few in our app by now, but yes, it looks like there aren’t many options.
