Adding a Button – JScript and Mashup

In this example I’ll show two simple examples how to add a button with JScript to a M3 form and also how to add a Button in a Mashup. I’ll add a button and make it launch something. Let’s start with the JScript.

The following example will add a button and when you click it you’ll launch a m3 program.
This is a good starting point for launching another app or a web page or whatever and by using script to get data from the panel you can send that information in the link you are opening.

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

package MForms.JScript {
   class ButtonExample {

      var content, debug, button;
      var controller;

      public function Init(element: Object, args: Object, controller : Object, debug : Object) {
         this.controller = controller;
         this.debug = debug;
         content = controller.RenderEngine.Content;

         var button : Button = new Button();
         button.Content = "Button 1";
         button.Name = "button1";
         Grid.SetColumnSpan(button, 10);
         Grid.SetRowSpan(button, 3);

         this.button = button;

      public function OnClick(sender: Object, e: RoutedEventArgs) {
         MessageBox.Show("Button 1 script");
         DashboardTaskService.Current.LaunchTask(new Uri("mforms://mms001"));

      public function OnRequested(sender: Object, e: RequestEventArgs) {

I had to add the namespace Mango.UI.Services which is a excellent namespace to have for all types of services. In this case I use DashboardTaskService to launch a Task. A task is something you can run. All applications in LSO uses an URI syntax. This way we can plug in any number of applications and one application is not just one form.

Also notice that I unregister the event handlers in the OnRequested method. This is extremly important. I don’t use the Unloaded method on for example the Button because objects might be pooled internaly by LSO.

Launching antoher application is done with DashboardTaskService.Current.LaunchTask(new Uri(“mforms://mms001”));

The button is placed in a grid on the form and here is what the example would look like in MMS001.

Add a Button to a Mashup

When you have a mashup you can boundle a complete set of different mashups and open a Mashup with data from another mashup.

Start by adding the Button. The configure the Event on the Button. Setting the property LinkUri will result in that link being opened.

<Button Content="Open MMS001" Width="100" Margin="8">
          <mashup:Event SourceEventName="Click" LinkUri="mforms://mms001">

If I wanted to open another mashup file in the same solution I would enter the relative path to that file. For example LinkUri=”Customer.xaml”. In order to pass parameters you specify the TargetKey and pass in the values. In my example below I use a converter to parse out the passed value that will be visible if the Mashup was opened by clicking the “Open again” button.

<Grid xmlns="" xmlns:x="" xmlns:ui="clr-namespace:Mango.UI.Controls;assembly=Mango.UI" xmlns:mashup="clr-namespace:Mango.UI.Services.Mashup;assembly=Mango.UI">
    <mashup:CurrentItemValue x:Key="CurrentItemValueConverter" />

    <ColumnDefinition Width="*" />
    <RowDefinition Height="Auto" />
    <RowDefinition Height="*" />
    <RowDefinition Height="Auto" />

  <Button Content="Open again" Width="100" Margin="8">
            <mashup:Event SourceEventName="Click" LinkUri="{Binding Path=Properties[RelativeUri]}">
              <mashup:Parameter TargetKey="Customer" Value="This is the passed value!" />
  <TextBlock Grid.Row="1" Text="{Binding Converter={StaticResource CurrentItemValueConverter}, ConverterParameter=Customer, Mode=OneTime}" HorizontalAlignment="Center" />

The path to the file itself is found in a Properties map with the key RelativeUri. This is just for the example to work without having to share a Mashup project. This could just as well be Customer.xml and the Value for the Parameter Customer you can bind that to whatever information you have available.

Happy coding!

4 thoughts on “Adding a Button – JScript and Mashup

    1. karinpb Post author

      There is an example in the Designer under Help -> Common Controls -> Window.
      You basically use the URL to the mashup and add a DefaultValues parameter. All parameters are combined in string with the following format”Name1;Value1;Name2;Value2″ This means that values are not allowed to have semicolon and that the entire string needs to be URL encoded in the JScript.

      Mashup URI: mashup:///?BaseUri=Karin5.mashup&RelativeUri=ChangeCustomer.xaml
      The BaseUri us the name of the mashup project file and the RelativeUri is the relative path to the XAML file. This way you can open Mashups that are not visible in the Navigator. To add parameters add the DefaultValues parameter. Then if you have a start up event you can pick the default values from any passed parameters.


    1. karinpb Post author

      Do you mean a button in a Mashup or with javascript in a H5 script?

      For Mashup look here:

      There is also a OptionButton that you can use – I have not used it myself but it was in the SDK documentation from the designer.

      Or do you mean JScript in Smart Office in MForms? Then you use the IInstanceController -> controller.ListOption(“F17”).

      If you mean in a javascript in the H5 web client then you also use IInstanceController -> controller.ListOption(“F17”).

      So please be more specific when you ask questions – you can never give too much information – but often too little.

Comments are closed.