AX Windows handling

I try to automat a sales order process in Microsoft Dynamics AX 2012.
The company has its warehouse only in Sweden but selling companies even in other countries like Norway, Danmark … Sales orders (SO) are created in the country where the customer is placed, but shipped from Sweden.
I need to find the SO from the swedish company, but there I can only delete the data for Sweden. I can press the button “Open original Sales Order” which is only available for not swedish SOs. A new window is opend where I can mark the lines and delete.
The problems are:

  1. the new window is exactly the same as the swedish one except for the company code in the header
  2. for Sweden no new window is opened and I can not use exception handling to find out if a new window was opened or not.
  3. the activities for Sweden and the other countries are exact the same
  4. I can not be sure that the latest opened window is the active one

I tried to solve it with a “Attach window” with a variable selector containing the company name where I can delete the rows.
I works quite ok, but I have not found a way to close the “swedish” window when I even opened another country window.
Closing the latest opened window works fine.
I tried with “Close window” both with a selector and with the ApplicationWindow variable. I save the ApplicationWindow on ‘Attach Window’ both from the first swedish window and then from the second ‘Attach Window’ in different variables.

We solved it our selves by just adding another “Attach window” for the swedish window and closed that instead.
I just wonder why “ApplicationWindow” does not give any effect.