I was requested to share some of my experience with MFORMS Automation and JScript.NET by Thibaud and here it is. MForms automation is simply a great alternative to perform data modification in M3, if you are left with no other option which was my case.
Problem
In our M3 implementation, we are using Std. Document Connect Media to deliver documents (example, Purchase orders) to our clients. These media entities like email addresses are setup in the program CRS945/949. This M3 program does not have an API implemented for data access. The alternative to using API was creating a Lawson Web service i.e. adding the customer to the program by simulating the panel sequence in LSO.
In CRS945, adding a document media control object involves the selection of document number (W1DONR). This step determines the kind of document selected and hence the other inputs (customer number, supplier ID or warehouse ID). In this example, document number 231 implies Order Confirmation document which requires a Customer number field which gets added to the panel.
Since the Customer Number gets added to the A-panel dynamically after the document number selection, creating a Lawson web service is not a possibility. This is due to the fact that Lawson Web Services designer does not allow “A or B Panel with ENTER followed by panels A, B” which is the case here. So web service was eliminated as an option which would have allowed us to add all the documents en masse by calling it repeatedly which was our requirement.
Solution
This left us with one and only option which was MForms automation. We ended up creating the MForms automation steps which would accomplish the task on hand and it looks as follows:
Note: Step command F3 which closes the panel is missing in this diagram. It is a critical step.
As you can see the sequence of steps are it easy to follow. Step one starts by running the program required which CRS945. In step two we end setting the value for the document number followed by an action step ‘ENTER’. Step 4 is another action which is to create the document connection. Finally we add the name and description for the connection and press ‘ENTER’. I have recreated these same steps using Jscript.NET and here it is:
As you can see the inputs for my MForms automations are provided from an Excel document (column 1: Document number, column 2: Customer number). This allows us to input multiple rows in one attempt. Running this Jscript using LSO on CRS945 adds the document connection for all our customers.
Regards
Seth Subramanian.
Hi, it is possible to do the “Add” operation via web service without any problem. But to do this, you must start in CRS027 and go via CRS945 to CRS949. Works as a charm. (But it is not possible to execute “Change”, “Delete” or “Display” in CRS949, because an invisible “Sequence” field is created in the background which cannot be set in the panel header, this field is set by selecting a record in the list -something what LWS/MWS can’t do.)
This approach works often if a field is missing when a program is wrapped via LWS/MWS: Go back one step if it is possible.I.e., you can enter line charges in CRS277 directly in M3, with LWS/MWS you can’t. But it is possible to start in CRS275 and go to CRS277 as related option in LWS/MWS and you have the full functionality in CRS277.
LikeLike
Thanks for sharing Seth!
LikeLike
Not a problem. I finally got some down time to complete this entry. I have been working on it for a while now.
LikeLike
Great work Seth! Have you looked into Heiko’s alternative solution?
LikeLike
HI Seth, I m trying to work with my very first jscript on M3. I need to update Fixed Assets records (FAS001) to create a link with Equipment (MMS240) . However, Script Tools send me the following msg : error JS1135: Variable ‘MFormsAutomation’ has not been declared
The “import MForms;” is included.
None of my colleagues were able to solve this case…
Thank you very much.
Pat’
LikeLike
Hi,
did you add …
import Mango.UI.Core.Util;
??
/Heiko
LikeLike
HI, thank you . The following statements are added :
import System;
import System.Windows;
import System.Windows.Controls;
import MForms;
import Mango.UI.Core;
import Mango.UI.Core.util;
import Mango.UI.Services;
In fact, I just copy and paste the template created by Seth…
Thank you.
Pat’
LikeLike
Hi again, you mistyped “util”. Must be “Util”, with capital “U”. Dotnet languages are case-sensitive.
/Heiko
LikeLike
Thank Heiko.
Shame on me.
The scritp is now compiled.
…I’m going to buy new glasses !
Thank you !
Pat.
LikeLiked by 1 person
Thank you for your Template, Seth. I’m now able to create the link between Fixed Assets and equipement transferred from SAGE. However, the Excel file is now locked. I tried to clear the Script cache, without success. Is there a specific command to release the Excel file ? Thank you again for your help.
Patrick
LikeLike
Patrick, peut-être il faut fermer Smart Office pour libérer le lock. /Thibaud
LikeLike
Salut Thibaud, Merci pour ta réponse. J’avais autant de process Excel d’ouvert que de tentatives d’exécution du jscript . Comme je les ai tous arrêté depuis le Task manager, je ne sais pas si cela suffit. Je viens de lire la réponse de Heiko, je vais essayer cette méthode qui semble plus intégrée. Connais tu un bon guide pour débuter le JSCRIPT ?Merci. Patrick
LikeLike
Pour debugger les scripts, il y a les logs debug.WriteLine, et encore mieux, le guide Script Assemblies: https://www.google.com/amp/s/smartofficeblog.com/2013/06/20/script-assemblies-in-mforms/amp/
LikeLike
Be aware that a script, when running in productive mode = raised from a panel, behaves completely different compared to a script started in the script editor. Therefore a logging function which can be turned on and off from outside by setting a script start argument is crucial. Use the log4net libraray to achieve this. Here is more information: https://smartofficeblog.com/2012/07/23/improvements-in-jscript-logging/
Even if you write compiled scripts in Visual Studio (C#-dll’s), logging remains important.
Also, be aware that when your script starts with a M3 panel, rendering has not finished, you can’t access any control without delaying the execution by using a dispatcher. When you are not using extended logging, you will never be able to trace what your script really does in case of errors. This is one of the main reasons where people get surprised – everything worked fine in the script editor, outside it doesn’t.
LikeLike
You can solve that problem with a delegate as explained by karinpb, like this:
LikeLike
Hi Patgro,
Excel as OLE object can be fully controlled from any external application. You can search the WWW for the objects workbook and excel.application.
workbook.Close(null, null. null) will close you workbook without changes.
Excel.Quit() will close the application.
Then set workbbook = null and Excel = null to be sure that you have no more references.
/Heiko
LikeLike
Many thanks for your answer, Heiko. I ‘ll try this method !
Patgro
LikeLike
HI, Many thanks for guiding us in many ways. I have tried following script for doing mforms automation to add the departure date in MWS410 via excel.
I got MNS921 popup box, and from that point onwards i am not able to access the text/date filed in the pop up box. How can i proceed or what is the correct name for the MNS921 pop box text/date field(WWVAL1)?
import System;
import System.Windows;
import System.Windows.Controls;
import MForms;
import Mango.UI.Core;
import Mango.UI.Core.Util;
import Mango.UI.Services;
import System.Threading.Thread;
package MForms.JScript {
class InactiveItems {
public function Init(element: Object, args: Object, controller : Object, debug : Object) {
var fso, f1, ts, s, rline;
var ForReading = 1;
fso = new ActiveXObject(“Scripting.FileSystemObject”);
ts = fso.OpenTextFile(“C:\Users\KesavanS\Desktop\OIS300 dep date\UpdateCO.csv”, ForReading);
while( !ts.AtEndOfStream ){
s = ts.ReadLine();
rline = new Array();
rline = s.split(“,”);
if(!trim(rline[0])== “”){
}
ts.Close();
MessageBox.Show(“done”);
}
public function reclassify(debug : Object, data : Object){
}
function trim(stringToTrim) {
return stringToTrim.replace(/^\s+|\s+$/g,””);
}
}
}
LikeLike
please find the correct code i used here with
import System;
import System.Windows;
import System.Windows.Controls;
import MForms;
import Mango.UI.Core;
import Mango.UI.Core.Util;
import Mango.UI.Services;
import System.Threading.Thread;
package MForms.JScript {
class InactiveItems {
public function Init(element: Object, args: Object, controller : Object, debug : Object) {
var fso, f1, ts, s, rline;
var ForReading = 1;
fso = new ActiveXObject(“Scripting.FileSystemObject”);
ts = fso.OpenTextFile(“C:\Users\KesavanS\Desktop\OIS300 dep date\UpdateCO.csv”, ForReading);
while( !ts.AtEndOfStream ){
s = ts.ReadLine();
rline = new Array();
rline = s.split(“,”);
if(!trim(rline[0])== “”){
}
ts.Close();
MessageBox.Show(“done”);
}
public function reclassify(debug : Object, data : Object){
}
function trim(stringToTrim) {
return stringToTrim.replace(/^\s+|\s+$/g,””);
}
}
}
LikeLike
Hi Kesavan, I do not know if M3 popups are supported by MForms Automation. Karin/norpe on the Smart Office blog may know. Otherwise, try MForms Bookmarks. Otherwise, you will have to make a manual test of entering data in the popup and submit, and look at the resulting HTTP request to see where the data is going in the XML; then reverse engineer the MForms Automation assembly, and see if there’s a hack you can do. Worst case, add the data directly to the field (TextBox via .NET reflection if Smart Office, or input field via JavaScript if H5 Client). Sorry, I don’t have a better answer right now. –Thibaud
LikeLike
Hi Thibaud,
Thank you.
will try with your suggestions. will let you know if i find any solution.
Kesavan
LikeLike
Great. And if you do find a solution, come write a blog post about it.
LikeLike
Hi,
I want to open OIS103 from OIS100 using MForms Automation, but as the OIS103 panel contains only read-only fields it doesn’t work. Is there is any way to use Automation on read-only fields?
LikeLike