Monday, February 1, 2010

Creating a M3 Web Service

I recently needed to use Lawson Web Services (LWS) for M3 to address some automation issues that APIs did not exist for.  LWS allows Web Services to programmatically access most M3 programs and function.

In this post I will show how to create a Web Service.  In a subsequent post I'll show how to consume this Web Service from Microsoft Excel.

Creating a Web Service to calculate the Cost of a variant (PCS230)

In this example we will start by loading PDS001, choose Related Options, Product Costing to start PCS230 and then run Costing for type 3 (standard):

Step 1 - Set programs to use A panel if possible
LWS works best with programs that can use the A panel.  We'll set PDS001 to use this:
Step 2 - Document the field names to enter data in programs/panels
When creating the Web Service we will need to specify the field names in panels we want to change
Step 3 - Document the key presses required
The Web Service will follow almost exactly the same key presses as is used in Workplace/Smart Client/Smart Office, so document the panel sequence, fields and keys pressed.

Our process is as follows
  • PDS001/A - Set WWFACI (Facility), W1PRNO (Product Number)
  • PDS001/A - Choose function 25 (Calculate Cost)
  • PCS230/E - Set WWPCTP (Costing Type), WWPCDT (Costing Date), WWCOUP (Calc purch/dist), WWPPRD (Purch price dt), WWSTRD (Structure Date), WWALVL (All levels)
  • PCS230/E - Press ENTER, then ENTER again (to accept the warning that the standard cost will be updated)
  • PCS230/F - Press ENTER
  • PDS001/A - Press F3 to exit the program
Step 4 - Build the Web Service in LWS
Note that you need to have LWS up and running.  Follow Lawson's instructions in the LWS Instllation Guide & User guide for this.  Check diagnostics in LWS to confirm that your setup is correct.  It should look something like this:

4.1 Create a new Web Service

4.2 Then define the parameters for the program to be called and test. This video is too large to embed here so click to see Web Service Creation Walkthrough

A few final notes about creation of Web Services:
  • When creating Web Services you can turn on the Interactive option for particular program/panels.  This is very useful to diagnose problems.
  • Web Services do not allow for branching logic within the Web Service. If you need to perform different actions based on the data, you will need to create a different Web Service for each action.
  • Not all programs allow for Web Services.  There appears to be a way to turn the warning off within LWS for this, however I have not yet tested this.