Geiger's Counter

Stuff I do with Lawson Smart Office

How to get the user password in a Smart Office script

with 4 comments

By Thibaud Lopez Schneider – April 11, 2012

Here is a solution to get the Lawson Smart Office user’s password with a Personalized Script.

This solution is interesting in scenarios where at runtime we need the current user’s password to dynamically integrate to external systems, for example to connect to a network drive, to connect to a secure website, to execute SQL, to call web services, etc. Also, this solution is interesting to call M3 API or to trigger PFI flows for early versions of Lawson Smart Office that don’t have those native adapters; late versions of Smart Office have native adapters to call M3 API and to trigger PFI flows without the need to obtain the user’s password.

It’s important to be careful with this solution to not transmit the password in clear text over insecure networks.

Also, note that this solution is not part of the official Smart Office API. Thus, the code can break with upgrades of Smart Office. To ensure the code doesn’t break, use only the official API of the Smart Office Developer’s Guide.

Here’s the source code of the solution:

import System;
import Mango.Services;

package MForms.JScript {
	class Test extends MarshalByRefObject {
		public function Init(element: Object, args: Object, controller : Object, debug : Object) {
			var userName : String;
			var password : String;
			ApplicationServices.UserContext.RequestCredentials("M3", "MForms", &userName, &password);
			debug.WriteLine(userName + ":" + password);

It’s interesting to note that with JScript.NET we can pass parameters by reference, by extending MarshalByRefObject and by using the ampersand character in front of a parameter, as we can do in C as in C#.

Here is a screenshot of the result:

Thanks to karinpb for the solution in C#, and to geiger for the solution in JScript.NET, and thanks again to geiger for letting me post his solution on his blog.

Thibaud Lopez Schneider


Written by thibaudatwork

April 11, 2012 at 12:30 AM

Posted in Uncategorized

Tagged with ,

4 Responses

Subscribe to comments with RSS.

  1. Is it possible to get the IP address of the server a user is accessing?


    May 9, 2014 at 11:09 PM

    • Hi Jean. Yes it’s possible. Are you writing a script for Smart Office? You have the M3 host in the system profile.


      May 10, 2014 at 10:28 PM

  2. Hi, would you have a sample whereby we can retrieve the m3 user’s role based on his user ID if we’re not calling the MNS410MI in the script? I’m able to retrieve the ID in my script but not sure how else to get the user’s role if the MNS410MI we use have only one transaction available and it doesn’t include the user id column. Also, like user id, cono, and divi, is there also an m3 specific field available for the user role? I look forward to your feedback, thanks.


    January 13, 2016 at 10:51 PM

    • Hi. If you are in a Smart Office script and you want the current user’s roles, you can just call the static IList MForms.UserContext.Roles. If you need somebody else’s roles you need to call the M3 API. If you want a list to your specifications, use SQL, or a custom list with CMS010. Hope it helps. /Thibaud


      January 13, 2016 at 11:57 PM

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 )

Google+ photo

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

%d bloggers like this: