Friday, April 17, 2009

Livecycle: Connecting to webservices through Javascript

This is extremely helpful in that you don't have to have hidden fields and have to worry about binding fields to webservices.

First things first, you have to know the address of the webservice. You may have made it through so other server, but if you had created it using livecycle (ie a webservice endpoint), you can either hardcode the address in (in which case skip to the Note), or you can dynamically establish the location of the server;
var server = event.target.URL;
Once you open the form inn WORKSPACE, server will contain an address. This address will contain the address of the server, it'll be in a format of;
http://wfdev:8080/workspace/tksdfjh

So what you'll have to do is to strip out the first part of the address;
server = server.substring(0,server.indexOf("/",8));

And you just tack on the endpoint to the server;
var myUrl = getServerURL.GetServerURL() + "/soap/services/myWebService?wsdl";

This makes it pretty handy if your webservice resides in a test server a prodction server (as an example) and you're transfering the form between servers and you don't want to have to keep changing the address.

******
Note: if your webservice is not on the Livecycle server, and the address is same no matter where you use the form, u can start from here
******

And then once you have the address you make a connection to it
var connection = Net.SOAP.connect(myUrl);
Now once you have this connection, you can call the methods of the service using the dot notation;
var result = connection.myMethod({"paramenter1": value, "parameter2":value2});

Note the way that the parameters are passed in.

No comments: