Compiled Scripts for Smart Office

Here is a solution in Lawson Smart Office to write “compiled scripts” in C# (as opposed to writing dynamic scripts in JScript.NET).


Traditionally, Personalized Scripts for Lawson Smart Office are written with the built-in Script Editor in the JScript.NET programming language and are deployed as plain text *.js files on the server.

There is also a less known technique. It is also possible to write scripts in C#, to compile them as DLL, and to deploy the *.dll file in lieu of the *.js file.

Pros and cons

There are several advantages of using C# versus JScript.NET. Mostly, the biggest advantage is the full richness of C#. Indeed, C# supports features that are not supported in JScript.NET, for example delegates. Also, C# is more extensively supported by Microsoft and by the community. Whereas JScript.NET is not fully supported by Microsoft, for example there’s no IntelliSense for JScript.NET in Visual Studio whereas there is IntelliSense for C#, and there are almost no examples for JScript.NET in MSDN whereas there are plenty for C#.

There are several disadvantages of using C# versus JScript.NET. Developing compiled scripts requires compiling the C# source code and deploying the DLL to run the script, which makes each iteration longer than developing with JScript.NET. Also, from the deployed DLL it’s not possible to directly see the source code, which is a problem if the source code is not available. Also, the script might need to be re-compiled for different versions of Smart Office, which could be a problem with upgrades.

Microsoft Visual C# Express

I will use Microsoft Visual C# Express to develop and compile my source code.

1) Find the Smart Office libraries

First, we need to find the Smart Office DLL as we’ll need to reference them in Microsoft Visual C# Express.

A user’s computer can run multiple instances of Smart Office at the same time, with different LSO version numbers, and different DLL version numbers. We want to find the correct DLL for our desired instance of Smart Office. There are two sets of DLL to find:

  1. Go to Smart Office
  2. Open the Help menu, it’s the question mark icon at the top right
  3. Select About Lawson Smart Office:
  4. Select View log file:
  5. That will open the Log Viewer
  6. Filter by message C:\ . That will show you the path to the Smart Office ClickOnce deployment folder in your computer, for example:
  7. C:\Users\12229\AppData\Local\Apps\2.0\Data\79O176HR.9F1\N42AOMBD.0HB\http..tion_2b27e2947dd74766_000a.0000_20a2b87dbe5264e8\
  8. Open that folder in Windows Explorer
  9. Search for the DLL files in all sub-folders. That will give us the first set of DLL, for example:
  10. The second set of DLL files is located in the other branch of the folder structure at C:\Users\12229\AppData\Local\Apps\2.0\. For example:

2) Create a Project

Now that we found the two sets of DLL files we can create a C# project in Visual C# Express and reference the DLL.

  1. Go to Visual C# Express
  2. Select File > New Project
  3. Select Class Library and give it a Name:
  4. Select Project > Properties, and make sure to use the same Target framework as your target Smart Office; for example, I use .NET Framework 4.0:
  5. Select Project > Add Reference:
  6. Browse to the first set of DLL found above:
  7. Then add the second set of DLL:
  8. Add the .NET components PresentationCore and PresentationFramework:
  9. Add System.Xaml:
  10. Add WindowBase:
  11. Select File > Save All, and choose a location to save your project.

3) Type the source code

Now we can start creating our script:
using System;
using System.Windows;
using System.Windows.Controls;
using MForms;
using Mango.UI;

namespace MForms.JScript
    public class Thibaud
        public void Init(object element, object args, object controller, object debug)

The result will look like this:

4)  Compile

Select Debug > Build Solution:

Visual C# Express will compile the code and produce a DLL file in the \obj\Release\ sub-folder of your project:

5) Deploy

Locate the jscript folder.

For Grid versions of Smart Office, the jscript folder is located in one of the LifeCycle Manager sub-folders, for example:


For non-Grid versions of Smart Office, the jscript folder is located in one of the WebSphere sub-folders, for example:


And copy/paste your DLL file there:

6) Execute

Now that the script is deployed on the server, we can execute it:

  1. Attach the script to the desired panel in Smart Office via Tools > Personalize > Scripts
  2. Set the Script value to the filename and .dll extension, for example Thibaud.dll:
  3. Click Add
  4. Click Save
  5. Press F5 to load and execute the script

7) Additional source code

If you need the controller, you will need to cast it from object to MForms.InstanceController.

InstanceController controller_ = controller as InstanceController;

If you need the content, you will need to cast it from object to System.Windows.Controls.Grid.

Grid content = controller_.RenderEngine.Content;

Now you can start developing your scripts, for example:

TextBox WRCUNM = ScriptUtil.FindChild(content, "WRCUNM") as TextBox;
controller_.RenderEngine.ShowMessage("The value is " + WRCUNM.Text);

Here is a screenshot of my sample script:

UPDATE 2012-04-25: Wayne L. found that we can also use a strongly typed signature for the Init method, so we don’t have to cast the objects anymore:

public void Init(object element, String args, MForms.InstanceController controller, MForms.ScriptDebugConsole debug) {


Thanks to Peter A.J. for the help.

Published by


M3 Technical Consultant

10 thoughts on “Compiled Scripts for Smart Office”

  1. please is there any way to put database connection in separate file so that all DLL files can use it instead defining it in each DLL.
    I mean something like
    using myCustomDbClass;


  2. on last version of SMO MUA web.xml should be changed otherwise You aren’t authorized to use dll’s.

        <display-name>Exclude from Security Constraint</display-name>
            <web-resource-name>Exclude from Security Constraint</web-resource-name>

    —> *.dll


    1. Thank you! Good to know. As a side note, all scripts should be delivered securely over HTTPS to avoid script injection (currently plain text HTTP). Maybe I should add that as a request for feature.


  3. Hi,
    Thanks for share this helpful information.

    I am new in SDK and JavaScript, can any one ever try to call SDK from java script.
    please let me know as i am not quit aware about it.



    1. If by JavaScript you mean JScript.NET, yes, from there we can call assembles written in C#, that’s what we do with every script. The reverse is true too, you can compile a JScript.NET to an assembly and call it from C#. It’s all .NET and interchangeable by the CLR.


    1. I don’t have sample code right now. There is the SDK documentation, Karin’s blog on the SDK, PotatoIT’s series on the SDK. Basically, follow the SDK documentation to drop the DLLs on the server, then call the assemblies in your script as usual.


Leave a Reply

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

You are commenting using your 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