How to tell Mashups apart in a Smart Office script

Here is a solution to tell in which Mashup a Personalized Script for Lawson Smart Office is currently running, for example to tell Mashups A and B apart in a script. We’ll read the BaseUri and Uri properties of a MashupInstance.

This solution is useful in scenarios where we have two Mashups, each with a specific script attached to a common M3 program. Each script needs to tell in which Mashup it’s currently running as we don’t want to let the scripts run in the wrong Mashup.

Example

For example, I have two Mashups that both use the M3 program Item Toolbox – MMS200.

The first Mashup (MashupA) shows a list of items and detailed information about a selected item, such as shelf-life, buyer’s name, on-hand availability in all warehouses, lot information, etc. In this Mashup, we need a script (ScriptA) to append an additional column of information to the list of items by querying a third-party warehouse management system. This Mashup is useful for the sales team to accurately communicate detailed information to a customer on the phone to convert a potential customer order and get the sale.

The second Mashup (MashupB) shows a list of items and purchasing information about a selected item, such as demand, supply, inventory, item specifications, sales history, forecast, etc. In this Mashup, we need a script (ScriptB) to append an additional column of information to the list of items by querying a third-party purchasing order software. This Mashup is useful for the purchase planning process when buyers need to decide if to buy an item or not and create a purchase order.

Both Mashups A and B have the same M3 program MMS200 in common, and two different scripts A and B. Each script needs to execute in its corresponding Mashup, script A in Mashup A, and script B in Mashup B. Otherwise, the scripts would show the wrong information in the wrong Mashup.

Problem

The problem is that when we attach a script to an M3 program in Smart Office, we cannot tell for which Mashup to execute the script. We can only attach the script to an M3 program, in my case to MMS200/B, and then attach the M3 program to the Mashup. But that doesn’t tell the script which Mashup is which.

More generally, Smart Office can only do binary relationships Mashup-Program and Program-Script, whereas we need ternary relationships Mashup-Program-Script. We are trying to solve that problem.

Solution

The solution is to get the identifier of the Mashup. Actually we cannot get the identifier of the Mashup as is defined in the Project’s manifest file. But we can derive one from a combination of the path of the Mashup, for example Mashups\MashupA.mashup, and the filename of the XAML, for example MashupA.xaml. That’s given by the Mashup’s BaseUri and Uri respectively.

For that, we’ll start with karinpb‘s solution to check if a JScript is running in a Mashup.

var element = controller.RenderEngine.ListControl.ListView;
var type = Type.GetType("Mango.UI.Services.Mashup.MashupInstance,Mango.UI");
var mashup = Helpers.FindParent(element, type);

That gives us a object that we can cast to MashupInstance from which we can get the  BaseUri and Uri properties:

mashup.BaseUri // ex: Mashups\MashupA.mashup
mashup.Uri // ex: MashupA.xaml

Here is a screenshot of the Smart Office SDK documentation:

Here’s my sample source code:

import System;
import Mango.UI.Services.Mashup;
import Mango.UI.Utils;

package MForms.JScript {
    class Test {
        public function Init(element: Object, args: Object, controller : Object, debug : Object) {
            if (controller.PanelState.IsMashup){
                var mashup: MashupInstance = Helpers.FindParent(controller.RenderEngine.ListControl.ListView, MashupInstance);
                switch (mashup.BaseUri + "\\" + mashup.Uri) {
                    case "Mashups\\MashupA.mashup\\MashupA.xaml": debug.WriteLine("MashupA"); break// MashupA
                    case "Mashups\\MashupB.mashup\\MashupB.xaml": debug.WriteLine("MashupB"); break// MashupB
                    case "Mashups\\MashupC.mashup\\MashupC.xaml": debug.WriteLine("MashupC"); break// MashupC
                    default: debug.WriteLine("Mashup not supported"); // Mashup not supported
                }
            } else {
                // Not in Mashup
                debug.WriteLine("Not in Mashup");
            }
        }
    }
}

Here are screenshots of the result:

Thanks to karinpb, Peter K, and Joakim I for their help.

That’s it!

Published by

thibaudatwork

ex- M3 Technical Consultant

One thought on “How to tell Mashups apart in a Smart Office script”

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 )

Connecting to %s