Here is a new solution to call SOAP Web Services from a Smart Office script that complements the previous known solutions. It’s a very easy and fast way to call LWS and does not require you to write any C# or XML.
It’s using a private API in Smart Office so it might change in future releases, without any announcement.
Here’s the result:
To consume Lawson web services in a script the WSDataService class is used. The class already exist in Smart Office and its placed in the Mango.Core.DynamicWs namespace.
It has a static method that does all the work for you:
public static void CallAsync( string wsdl, string contractName, string operationName, Dictionary<string, object=""> parameters, Uri address, WSDataService.WSDataServiceCallbackDelegate callbackDelegate, bool useBasicHttp = false, string userName = null, string password = null, string maxReceivedMessageSize = null)
And here’s an example when using the method:
import Mango.Core.DynamicWs; package MForms.JScript { class WebserviceTest { public function Init(element: Object, args: Object, controller : Object, debug : Object) { var p = new TypeObjectCollection().GetValues(); p.Clear(); p.Add("W1CUNO", "10001"); WSDataService.CallAsync("http://mylws/service/address?wsdl", "MMS001_CUSTOM", "MMS001_CUSTOM", p, new Uri("https://mylws/service/address"), CallbackDelegate, true, "username", "password"); } public function CallbackDelegate(result: Object, message: String, ex: Exception, operation: String) { Debug("Operation: " + operation); Debug("Message: " + message); if (ex.InnerException) Debug("Exception: " + ex.InnerException.Message); else Debug("Exception: " + ex.Message); Debug("Result: " + result); Debug("-----------"); } } }
I didn’t manage to create a dictionary in JScript so I use a method that returns one, then clears it. Might need some improving.
UPDATE – JUN 14 2013:
To send parameters to the webservice the keys in the dictionary have to have the exact binding names, or they wont be sent at all.
One way to find the names is by using the WsTest tool.
- Start Smart Office and then the tool by typing “tool://wstest”.
- Enter the wsdl and hit “Load”.
- Uncheck the checkbox called “Show tree view” and scroll down to your parameter.
- There you can see all the names and right click to copy one.

/Erik
Great post Erik! Thank for this “fifth solution” and now the best. /Thibaud
LikeLike
I agree with Thibaud. Top shelf solution! ….Tested also with the stored procedure web service variant that Web Service Designer/Runtime offer, but using CSharp flavor ala https://thibaudatwork.wordpress.com/2012/04/24/compiled-scripts-for-smart-office Conny E. and LSO dev, keep up the good work — I hope this API is here to stay.
LikeLike
Hi Eric,
I was able to execute the web service and retrieved a result value, but it seems to be only a string containing the method name, and “ResponseType” added – in my example CRS277_GetResponseType. I can see the structure of the full SOAP response in Fiddler, but how can I access the fields in the “result” return object from my JScript ? /Heiko
LikeLike
Hi, it may look like a string but doing a WriteLine() on an object will output the name of the type. So if you look in your response xml, locate the element with that name and try to access its children on your response object.
Maybe something like: result.CRS277.W1CUNO
Have you also tried the tool://wstest ? You should be able to see the types and properties there.
Or, you could always browse to the wsdl location and take a look at the type structure (though it could be a bit messy)
LikeLike
Thank you!!
I used this approach for an external soap webservice. Works good.
You saved my day with this 😉
Keep up the good work!!
LikeLike
Thank you Frode for the feedback. Glad it worked.
LikeLike
How can we call the SQL WS from the smart office and pass them multiple values from the excel sheet.
LikeLike
Hi Kiran, you can create a VB macro in Excel that loops thru the spreadsheet and calls LWS for each row.
LikeLike
I want to know can we set the values to the uneditable fields using Smart Office Scripting.
for ex:I need to call MMS121 from MMS080 adn need to pass some values and set it in MMS121 but i am not able to do so ,
Actually I get an error saying Failed to comply request
Might this be because fields no MMS121 are not editable.
please help if you any idea
LikeLike
If the field is not editable there’s nothing the web service can do since it simulates a user. The alternatives are: M3 API, MForms Automation, or Bookmarks.
LikeLike
Hi!
thanks for this good explanation.
I have a bit the same problem as Heiko.
I don´t get the values from the object. When I get the object type and compare that with the type structure on the wsdl page it seems it is on the wrong “sub type”.
For example I do this “result.GetType();” and the result is “YXResponseType”
When I look on the wsdl page I see now:
Main transaction
YXResponseType
new0Collection
new0collectionType
new0Item
new0ItemType
My value 1
My value 2
The fiddler result looks good to me:
– Transaction response
new0collection
new0Item
My Values
Any idea?
Thanks in advance!
LikeLike
Hi Daniel, I learned a lot in the meantime, and this is very simple. It depends on the name that you applied in the web service for your result set.
Default is “new0”. But you can change it in the designer, above the result fields. I always give my resultset in the MWS designer a meaningful name.
If your object name in the CallBackDelegate is “result”, you can do:
var items = result.new0Collection;
now loop your resultset:
for (var record in items)
yourVariable = items[record].YourFieldName;
…
if yourVariable is a String you will have trailing blanks, so better add …Trim().
A good written SQL at the right place can be faster then an API. And you can even create StoredProcedures and wrap it via MWS.
LikeLiked by 1 person
Hi Heiko,
My script works now without any problem!
Thank you for your help!
LikeLiked by 1 person