Buttons and Smart Office

One of the things that I have found, not being a ‘professional’ developer is that often I get tripped up by the idiosyncrasies of the tools. It’s probably worth noting that these are just my experiences and aren’t necessarily correct J

Smart Office and jscripts was certainly no exception. The issue comes down to my inclination to work iteratively on projects. Develop the basic framework, test, add some more basic code, test, add more code, test and so on. A process that got me tripped up with some inconsistent results.

The task that I needed to complete was, add a button to MWS420, this button would call Related Option 11 (which takes the user to MWS422). Then add a button to MWS422 for Related Option 11.

It should be easy you’d think, but what I have previously mentioned it became rather challenging as sometimes the code in Smart Office would become ‘disassociated’ with the panel I was working with, or partially ‘corrupt’ when I was iterating through my changes giving me somewhat odd results. Coming from a world of Microsoft Visual Studio I would expect that when I compile and then run a script, I would always be running only the latest of changes – this is not the case.

So anyway, the task at hand, very easy once you know what you are doing.

import System;

import System.Windows;

import System.Windows.Controls;

import MForms;

import Mango.UI.Core;

import Mango.UI.Core.Util;

import Mango.UI.Services;

package MForms.JScript

{

class MWS420_SelectOrder

{

var debug, button, content, gcontroller;

public function Init(element: Object, args: Object, controller : Object, debug : Object)

{

this.gcontroller = controller;


content = controller.RenderEngine.Content;


button = new Button();

button.Content = “Select Order”;

Grid.SetColumnSpan(button, 10);

Grid.SetColumn(button, 10);

Grid.SetRow(button, 6);

content.Children.Add(button);

button.add_Click(OnClick);

button.add_Unloaded(OnUnloaded);

}


// We will use the interactive launching of the Normal Option

private function listOptionNormal()

{

try

{

if(null != gcontroller)

{

gcontroller.ListOption(“11”);

}

else

{

MessageBox.Show(“Controller Class not initiated”);

}

}

catch(ex)

{

MessageBox.Show(“Exception: “ + ex.Message);

}

}


public function OnClick(sender: Object, e: RoutedEventArgs)

{

listOptionNormal();

}

public function OnUnloaded(sender: Object, e: RoutedEventArgs)

{

button.remove_Click(OnClick);

button.remove_Unloaded(OnUnloaded);

}

}

}

There is another method to invoking the functions, and that is through the Automation, though it looks like the automation creates new instances, and doesn’t retain a relationship to originating caller which means that it is of no use to us, but I have included the code for the sake of interest.

// Use Automation to fire Option 11 in MWS420.

// Automation will not run in the same instance, it will create a new instance

private function listOptionThroughAutomation()

{

// we try {} catch() {} in order to allow us to gracefully handle errors

try

{

// create a new MFormsAutomation object

var mfaAutomation = new MFormsAutomation();

if(null != mfaAutomation)

{

// in our first step we run MWS420 as we can’t directly run

// MWS422

mfaAutomation.AddStep(ActionType.Run,“MWS420”);

// mfaAutomation.AddStep(ActionType.Key,”ENTER”);

mfaAutomation.AddStep(ActionType.ListOption,“11”);

var uri = mfaAutomation.ToUri();

//MessageBox.Show(uri);

DashboardTaskService.Manager.LaunchTask(new Task(uri));

}

else

{

MessageBox.Show(“Failed to create MFormsAutomation class”);

}

}

catch(ex)

{

MessageBox.Show(“Exception: “ + ex.Message);

}

}

This entry was posted in Development, M3 / MoveX. Bookmark the permalink.

One Response to Buttons and Smart Office

  1. Frode says:

    Hi , and happy 1st birthday!

    I have a task to make some “automation” script, and have tried to use the above controller.
    The task is:
    PMS230/B1 select a row in list and press my scritpbutton “Print”. This fires ListOption(“6”)/print. That takes me to PMS250/B where i should use ListOption(“1”)/Create, but since this is a new instance I have lost control… :-/
    There are a few steps more, but if I get this sorted out they will be no problem.
    Whattodo?

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s