How to call Lawson Web Services from PHP

Here are examples to call Lawson Web Services from PHP for all three adapters: API, M3 Display Program (MDP), and SQL.

Which SOAP client ?

In the past, I used the external NuSOAP toolkit to make SOAP calls in PHP.

Now, PHP 5 comes built-in with SoapClient.

To determine which SOAP client your PHP server provides, use:

phpInfo();

It will show:

What’s the Endpoint ?

To determine the endpoint or the WSDL to our Lawson Web Service open the Lawson Web Services Runtime Management Page which you can launch from LifeCycle Manager or from Lawson Web Services Designer.

Select List, select the Service Context, and select the Web Service.

The bottom right corner will show the WSDL Address:

How’s the SOAP ?

I recommend using tools like Fiddler or soapUI to determine the exact structure of the SOAP Request and SOAP Response to call our Lawson Web Services.

Fiddler can intercept HTTP calls from most SOAP clients, for example from Lawson Web Services Designer, from Microsoft InfoPath, from PocketSOAP, or from Microsoft Visual C# Express, and we can use that SOAP Request and SOAP Response as a reference to write our PHP code:

Similarly, soapUI will create a sample SOAP Request from a WSDL, it will show the SOAP Response after the web service is executed, and we can use that SOAP Request and SOAP Response as a reference to write our PHP code:

M3 API adapter

Here is a sample PHP code to call a Lawson Web Service of type API.

The Web Service name is Customers, the operation name is LstByNumber. It calls the API CRS610MI.LstByNumber. It accepts Company and CustomerNumber as input fields; note the suffix Item in LstByNumberItem for the collection of input fields. It returns CustomerNumber and CustomerName as output fields; note the suffix ResponseItem in LstByNumberResponseItem for the collection of output fields.

<?php
	try {
		$client = new SoapClient("http://hostname:10000/LWS_DEV/svc/Customers.wsdl",
		array(
			'login'=>'M3SRVADM',
			'password'=>'*******'
		)
		);
		$response = $client->LstByNumber(array("LstByNumberItem"=>array(
			"Company"=>"001",
			"CustomerNumber"=>"00100001"
		)));
		foreach ($response->LstByNumberResponseItem as $item) {
			print($item->CustomerNumber." ".$item->CustomerName."\n");
		}
	} catch (Exception $e) {
		echo 'Message: ' .$e->getMessage();
	}
?>

M3 Display Program adapter

Here is a sample PHP code to call a Lawson Web Service of type M3 Display Program (MDP).

The Web Service name is Customers, the operation name is GetName. It works in CRS610/A/E, it accepts W1CUNO as an input field, and returns WRCUNM as an output field.

<?php
	try {
		$client = new SoapClient("http://hostname:10000/LWS_DEV/svc/Customers.wsdl",
		array(
			'login'=>'M3SRVADM',
			'password'=>'*******'
		)
		);
		$response = $client->GetName(array("CRS610"=>array(
			"W1CUNO"=>"0010001"
		)));
		print($response->CRS610->WRCUNM);
	} catch (Exception $e) {
		echo 'Message: ' .$e->getMessage();
	}
?>

SQL adapter

Here is a sample PHP code to call a Lawson Web Service of type SQL (JDBC).

The Web Service name is Customers, the operation name is Search. It works by doing a SELECT FROM WHERE on OCUSMA, it accepts CustomerName as an input field. And it returns OKCUNO and OKCUNM as output fields; note the new1Collection and new1Item automatically generated.

<?php
	try {
		$client = new SoapClient("http://hostname:10000/LWS_DEV/svc/Customers.wsdl",
		array(
			'login'=>'M3SRVADM',
			'password'=>'******'
		)
		);
		$response = $client->Search(array("CustomerName"=>"%ARMY%"));
		foreach ($response->new1Collection->new1Item as $item) {
			print($item->OKCUNO.", ".$item->OKCUNM."\n");
		}
	} catch (Exception $e) {
		echo 'Message: ' .$e->getMessage();
	}
?>

That’s it!

Related articles

Published by

thibaudatwork

ex- M3 Technical Consultant

12 thoughts on “How to call Lawson Web Services from PHP”

  1. Thibaud I need help in calling the web service which is going to update MMS001’s 22 fields onthe basis of ITNO,If you will provide your Macro code calling MMS010 in your video I will be very grateful,Thanks in advance.

    Like

  2. Hi Thibaud
    i was calling the lawson web service using the excel macro
    when i see the node log history i get this error

    WS-CXF: Interceptor for {http://lawson.com/ws/credentials/GeoCodes}GeoCodesService has thrown exception, unwinding now (WARNING : org.apache.cxf.phase.PhaseInterceptorChain)
    please reply

    Like

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s