Friday, October 11, 2013

How to Perform REST Call from BPM Server Script

IBM BPM has provided a java connector in the system toollkit which will help performing this rest operation. But that is not very robust and doesn't allow us to perform all the kinds of REST operations. In this post I would like to illustrate on how to invoke a REST service from a server script.
Below is the script which can be used to perform a Rest Call from BPM Server sccript.

var client = new;
var op = new;

op.setParameter("param 2",tw.localvar2);


var auth = new"restapiuser","restapipass");
client.getState().setCredentials(null, null, auth);

try {
  var statusCode = client.executeMethod(op);
  tw.local.output = op.getResponseBodyAsString();

} finally {

parse the status

    tw.local.instanceId= tw.local.response.getElementByTagName("data").item(0).getElementByTagName("element").item(0).getText();
  //  tw.local.instanceId=tw.local.response.toString(true);

Also check the post to perform rest call in IBM with input as Entity.
Hope this post is help full !!!

Thanks for stopping by. If you like this post leave a comment, share it and do a g +1.

Wednesday, October 2, 2013

How to Convert TWObject to JSON

JSON has been very famous now a days, especially while using REST.
Here is the script to create a JSON out of a teamworks object.

Say I have tw object of type EMPLOYEE with the parameters (name, place,phone). After executing the script below it will give the JSON as below.


result :

tw.local.json  will have the value {"Employee":{"name":"abcd","place":"ongole","phone":"xxxxxx"}}