LSO & API/MI – a guest post

A couple of weeks ago I got an email from Jonas to share discussing using the APIs from LSO 10 – which is fantastic timing as we have recently upgraded. As I am sure most of you are aware, version 10 of LSO allows you to call APIs directly. So here it goes – enjoy:


Useful info perhaps, hope it will give you some nice ideas – API:s are good to both get and in some cases create data..

API/MI in scripts in short (using LSO 10) – probably left out some variable declarations but you will probably get the concept.

Don’t forget MNS185 and CRS990MI/GetBrowse if there are no API:s for data that you wish to get, you can create your own selection and even with filters, quite powerful imho..

Example to call API from LSO..

import Lawson.M3.MI;

public function ApiExample()
                             var api = "MMS200MI"; 
                             var transaction = "GetItmBasic"; 
                             var record = new MIRecord(); 
                             record["CONO"] = UserContext.CurrentCompany;
                             record["ITNO"] = itemNumber; 
                             MIWorker.Run(api, transaction, record, NextStepFunctionHere); 

private function NextStepFunctionHere (response:MIResponse) 



Alternative when create data or execute multiple api calls in same function and handle a possible returnError and display to user or log.

var api = "MMS200MI"; 
var transaction = "GetItmBasic"; 
var record = new MIRecord(); 

record["CONO"] = UserContext.CurrentCompany;
record["ITNO"] = itemNumber; 

response = MIAccess.Execute(program, transaction, record); 
                             if(response.HasError) {
                                      returnError="Error in API transaction:" + response.ErrorMessage;

itemDescription = response.Item.GetString("ITDS");


…and another nice feature:

How to write to the LSO log with script debug data:

// Declare before init:
var logger: log4net.ILog = Mango.Core.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);

// Call to the function:
WriteLog("This is an example of debug logging to lso log”);

private function WriteLog(logText: String){
This entry was posted in Uncategorized. Bookmark the permalink.

2 Responses to LSO & API/MI – a guest post

  1. mikael says:

    Hi. What is the correct and best way to create dummy API. Is it to use MNS185 and CRS990MI/GetBrowse or the new MDBREADMI ? Thank for nice blog ! /Mikael

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 )

Connecting to %s