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) { itemDescription=response.Item.GetString("ITDS"); itemDescription2=response.Item.GetString("FUDS"); doSomethingWithThis(); }
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; return; } 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){ if(message!=null){ logger.Debug(logText); if(debug){ debug.WriteLine(logText); } } }
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
My vote goes to MDBREADMI!