April 24, 2012 2:18 pm
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.
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.
I will use Microsoft Visual C# Express to develop and compile my source code.
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:





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








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:
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:
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:
\\hostname\d$\Lawson\LifeCycleManager\Service\<service>\grid\<profile>\applications\LSO_M3_Adapter\webapps\mne\jscript\
For non-Grid versions of Smart Office, the jscript folder is located in one of the WebSphere sub-folders, for example:
\\hostname\d$\IBM\WebSphere7\AppServer\profiles\MWPProfile\installedApps\MWPProfileCell\MWP_EAR.ear\MNE.war\jscript\
And copy/paste your DLL file there:
Now that the script is deployed on the server, we can execute it:

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) { }
Voilà!
Thanks to Peter A.J. for the help.
Posted by thibaudatwork
Categories: Infor Smart Office Scripts
Tags: M3, Script, Smart Office
Mobile Site | Full Site
Get a free blog at WordPress.com Theme: WordPress Mobile Edition by Alex King.
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;
?
LikeLike
By Ashraf Abd-Elfattah on March 1, 2015 at 4:55 am
Hi, yes, to write separate class you’ll need script assemblies in C#, check https://thibaudatwork.wordpress.com/2012/04/24/compiled-scripts-for-smart-office/ and http://smartofficeblog.com/2013/06/20/script-assemblies-in-mforms/ and https://potatoit.wordpress.com/2011/05/11/calling-your-own-assembly-from-jscript/ . Otherwise, you can load your own assembly with System.Reflection https://thibaudatwork.wordpress.com/2011/08/25/send-sms-from-smart-office/
LikeLike
By thibaudatwork on March 2, 2015 at 4:17 pm
on last version of SMO MUA web.xml should be changed otherwise You aren’t authorized to use dll’s.
—> *.dll
GET
LikeLike
By Antonio Caria on May 14, 2016 at 2:38 pm
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.
LikeLike
By thibaudatwork on May 16, 2016 at 6:42 am
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.
Thanks
LikeLike
By farhat on October 20, 2016 at 3:10 am
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.
LikeLike
By thibaudatwork on October 20, 2016 at 9:26 am
Thanks for reply,
can you please share some sample code if possible.
Regards
Farhat Khan
LikeLike
By farhat on October 26, 2016 at 2:07 am
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.
LikeLike
By thibaudatwork on October 26, 2016 at 2:12 am
Farhat, refer to Smart Office SDK > Developers Guide > Chapter 7 Package and deploy
features
LikeLike
By thibaudatwork on October 26, 2016 at 3:13 pm
[…] Compiled Scripts for Smart Office […]
LikeLike
By Site map – M3 ideas on May 9, 2017 at 12:27 pm