For easy access to M3 APIs we have created a few classes that you can use both in your JScripts and in your features. For those of you who don’t know the difference, JScripts are used on a standard M3 and S3 forms to add new functionality. A feature is an application that runs natively within Lawson Smart Office. This is the way we build the UI to our applications such as M3, S3, LBI, Process Server, Document Archive… to mention a few.
I got a question from one of our Solution Consultants, Peter Johansson. He was using MIAccess to get customer data but he was experience delays due to the amount of data.
“Is there a way to specify which fields should be returned by the API?”
Of course there is!
And this is how you do it:
private void FindCustomers(object sender, RoutedEventArgs e)
{
var api = "CRS610MI";
var trans = "LstByNumber";
var record = new MIRecord();
record["CUNO"] = txtCustomerNumber.Text;
var outparms = new MIParameters
{
OutputFields = new String[] { "CUNO", "CUNM", "PHNO" }
};
MIWorker.Run(api, trans, record, OnCompleted, outparms);
}
private void OnCompleted(MIResponse response)
{
CustomersList = new List<Customer>();
foreach (var itm in response.Items)
{
var tmpCustomerNumber = itm.GetString("CUNO");
var tmpCustomerName = itm.GetString("CUNM");
var tmpPhoneNumber = itm.GetString("PHNO");
CustomersList.Add(new Customer { CustomerName = tmpCustomerName, PhoneNumber = tmpPhoneNumber, CustomerNumber = tmpCustomerNumber });
}
// Databind the UI list to the response.
lstCustomers.ItemsSource = CustomersList;
}
Lawson.M3.MI.MIWorker has a set or Run methods. You pass in your delegate and once the call is done your callback method, in this example OnCompleted will be called on the UIThread. In his example Peter gets the data and place it in a Customer object but you could just as well bind the datasource directly to the response.Items collection. In that case use the indexer in the same way you do in Mashups, [“fieldName”].
Happy Coding!
And a special thanks to Peter Johansson for submitting the final result to me. MIAccess is available in LSO 9.1.3.
*edit*
For a richer example of Calling a M3 APIs in JScript check out this post, Validating M3 panels using JScript and MI programs before a request
Pingback: Calling M3 APIs « M3 ideas
Pingback: How to add a column to a list « M3 ideas
Pingback: How to get the user password in a Smart Office script « Geiger's Counter
Pingback: How to get the user password in a Smart Office script « M3 ideas
How do you do this will JScript?
Replying to my own comment… the code below would work with JScript…
//private void FindCustomers(object sender, RoutedEventArgs e) { // bad. This is like C# impl
//function FindCustomers(sender : Object, e : RoutedEventArgs) { // better implmentation for JScript.Net
//function FindDeliveryMethods(sender : Object, e : RoutedEventArgs) { // if you set up listener
function FindDeliveryMethods() {
var api = “CRS070MI”;
var trans = “LstDelyMethod”;
var record = new MIRecord();
//var MyIntArray : int[] = new int[5];
//var outParameters : String[] = ["CUNO","CUMN","PHNO"];
//var outParameters = new MIParameters();
//var outputParams = new MIParameters(new String[]{“CUNO”,”CUMN”});
var fields : String[] = ["MODL","LNCD","TX15","TEL2"]; //this works
//var fields : String[] = new String[4]; // this works too
//fields[0] = “MODL”;
//fields[1] = “LNCD”;
//fields[2] = “TX15″;
//fields[3] = “TEL2″;
var outParameters = new MIParameters(fields);
MIWorker.Run(api, trans, record, OnCompleted, outParameters);
}
private function OnCompleted(response : MIResponse) {
//CustomersList = new List(); // C# not JScript.Net
//foreach (var itm in response.Items) { // this is VB programming ; just use for-loop
for (var itm in response.Items) {
var tmpDeliveryMethod = itm.GetString(“MODL”);
var tmpLanguage = itm.GetString(“LNCD”);
var tmpName = itm.GetString(“TX15″);
var tmpFedExCode = itm.GetString(“TEL2″);
debug.WriteLine(“MODL: “+tmpDeliveryMethod+”,\tLNCD: “+tmpLanguage+”,\tTX15: “+tmpName +”,\t TEL2 – FedExCode: “+tmpFedExCode);
//CustomersList.Add(new Customer { CustomerName = tmpCustomerName, PhoneNumber = tmpPhoneNumber, CustomerNumber = tmpCustomerNumber });
}
// Databind the UI list to the response.
//lstCustomers.ItemsSource = CustomersList;
}
Hi, There are many examples on the blog the uses M3 APIs, so check those for JScritp syntax. Here is one http://lawsonsmartoffice.com/2012/03/30/validating-m3-panels-using-jscript-and-mi-programs-before-a-request/.
. It could have been (becuase VB has foreach) -but is isn’t.
Or – perhaps better – check MSDN JSCript reference giude: http://msdn.microsoft.com/en-us/library/x85xxsf4(v=vs.100).aspx
And one note on your solution – the code on this blog is never VB