Tag Archives: #dialog

Creating your own windows with JScript

When working with JScript you might want to open a new window. There are a few different ways that this can be done and today I’ll share how to create a new window that is visible in the taskbar and how to open a modal window. Modal means that you cannot access any other Smart Office functionality such as the QuickNote widget or data in a form as the modal window is the only currently active window placed above all other windows. A modal window is a graphical control element subordinate to an application’s main window which creates a mode where the main window can’t be used. The modal window is a child window that requires users to interact with it before it can return to operating the parent application, thus preventing the workflow on the application main window. This is great for some cases but can also be frustrating.


Some of the concepts when working with windows in Smart Office is IInstanceHost – which represents the contract to an application host window. Then if a window is visible in the TaskBar it has to have a Runner – a handle to a task running on the Canvas. A Task is an item that can be launched on the Canvas. A task can only be launched if there is a registered application that supports the task. The scheme part of the task URI is used to locate an application that can launch a specific task, form example mforms://mms001. All these interfaces and classes can be found in the Smart Office SDK API and some of them in the API Documentation under Help in the Mashup Designer. When writing JScripts you should be familiar with the Smart Office core programming concepts.

There are new overloads of LaunchTask that can open a window in different ways. If the code does not work on your version of Smart Office it is possible that the method used does not exist in your version.

Opening a new window

Below is an example from Norpe on how to create a non modal and a modal window with JScript. Enjoy.

If you don’t want to have modality to the new window you can create a window that shows up in the task bar using an overload of the LaunchTask method. The script below shows examples of how to launch a modal window and a non-modal window.


import System;
import System.Windows;
import System.Windows.Controls;
import MForms;
import Mango.UI.Core;
import Mango.Services;
import Mango.UI.Services;

package MForms.JScript {
   class NewWindowTest {
      var controller, content, debug, host;
      var buttonOpen, buttomOpenModal, buttonClose;
      public function Init(element: Object, args: Object, controller : Object, debug : Object) {         
         this.controller = controller;
         this.debug = debug;
         var content : Object = controller.RenderEngine.Content;

         var stackPanel = new StackPanel();
         stackPanel.VerticalAlignment = VerticalAlignment.Center;
         stackPanel.HorizontalAlignment = HorizontalAlignment.Center;

         buttonOpen = new Button();
         buttonOpen.Content = "Open New Window";
         buttonOpen.Width = "160";
         buttomOpenModal = new Button();
         buttomOpenModal.Content = "Open New Modal Window";
         buttomOpenModal.Width = "160";
         buttomOpenModal.Margin = new Thickness(0,8,0,0);
         Grid.SetRowSpan(stackPanel, 100);         
         Grid.SetColumnSpan(stackPanel, 100);

      public function OnClickOpen(sender: Object, e: RoutedEventArgs) {         
         try {
            var title = "New Window Test";
            var task = new Task(new Uri("notused://")); // The uri is not important (but must be valid) when shortcut are not allowed
            task.AllowAsShortcut = false;
            task.VisibleName = title;
            task.ToolTipInfo = title;
            task.UseVisibleShortName = false;
            var runner = DashboardTaskService.Current.LaunchTask(task, HostType.Default);
            host = runner.Host;
            host.HostContent = CreateWindowContent("Window Content");  
            host.HostTitle = title;
            host.Width = 640;
            host.Height = 480;
            runner.Status = RunnerStatus.Running;
         } catch(ex) {
      public function OnClickOpenModal(sender: Object, e: RoutedEventArgs) {         
         try {
            var content = CreateWindowContent("Modal Window Content");  
            content.Width = 640;
            content.Height = 480;
            var title = "New Modal Window Test";
            host = new HostWindow(true);
            host.HostContent = content;
            host.HostTitle = title;
            DashboardService.Current.ShowDialog(host); // Use DashboardService to get modal "shake".
         } catch(ex) {
      public function CreateWindowContent(text : String)
         var grid = new Grid();
         var textBlock = new TextBlock();
         textBlock.Text = text;
         textBlock.VerticalAlignment = VerticalAlignment.Center;
         textBlock.HorizontalAlignment = HorizontalAlignment.Center;
         textBlock.FontSize = 48;
         buttonClose = new Button();
         buttonClose.Content = "Close";
         buttonClose.Width = "120";
         buttonClose.VerticalAlignment = VerticalAlignment.Bottom;
         buttonClose.HorizontalAlignment = HorizontalAlignment.Right;
         buttonClose.Margin = new Thickness(0,0,8,8);
         return grid;
      public function OnClickClose(sender: Object, e: RoutedEventArgs) {         
         if(host != null) {
            host = null;
      public function OnRequested(sender: Object, e: RequestEventArgs) {
         if(buttonClose != null) {
      function Log(text : String)