Saturday, April 18, 2015

Working with JSON in IBM BPM

Now a days REST protocol has become very popular for interaction between various system. REST services support both json as well as xml as i/o. In this post, I would like to illustrate with an example on how to parse the json response / json object to retrieve the data and assign it to a tw variable by using json2.js file.
Let us first attach the file json2.js to the files sections under server files as shown below.

Figure 1

Thursday, April 16, 2015

Performing REST Call from IBM BPM server Script

IBM BPM provide a connector "read from http" in system toolkit to invoke the REST service call. This connector supports both get and post methods while invoking the REST Service. But the disadvantage with this is that it will support only when the input is in the form of either query parameters or form parameters, but not when the input has to be sent as Entity to the REST service.
  
In this Post, I would like to illustrate an example on how to perform a rest call which where the input has to be passed an entity  instead of name and value as illustrated in my other post.

Below is the xml input which has to be passed to the rest service. let us use a server scriptlet to bind this input xml to the variable tw.local.inputString.


Input:



<Reqest><control>420131</control><suffix>10</suffix> <account>1</account><planData><planNumber>21</planNumber><planEffectiveDate>2014-01-10</planEffectiveDate></planData></Request>

Below code can be to invoke the rest service by passing the necessary input to the service call. 


var client =new Packages.org.apache.http.impl.client.DefaultHttpClient();

var input =new Packages.org.apache.http.entity.StringEntity(tw.local.inputString);
input.setContentType("application/xml");
var post = new Packages.org.apache.http.client.methods.HttpPost(tw.local.restserviceurl);
post.setEntity(input);
var response = client.execute(post);
//var entity = response.getEntity();
tw.local.output = Packages.org.apache.http.util.EntityUtils.toString(response.getEntity(),"");


Below shown is the xml output the above response, which is in String format.



<Response>   <getCount>    <planNumber>21</planNumber>
    <planEffectiveDate>2014-01-10</planEffectiveDate>     <subscribers>0</subscribers>     <members>0</members>  </getCount>   <getCount>    <planNumber>0</planNumber>    <planEffectiveDate />    <subscribers>0</subscribers>    <members>0</members>  </getCount>  </Response>

After getting the response as a string, you can convert that to XML as below:

tw.local.response = Packages.com.lombardisoftware.core.XMLUtilities.stringToElement(tw.local.output);

you can also refer the post on how to convert XML string to XML.

Hope this post is usefull !!!

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

Saturday, April 11, 2015

Server side Caching in IBM BPM with jsCache

Many of us might come across this requirement of server side caching mechanism in IBM BPM, especially when the applications are UI heavy, involves lots of users or expensive data preparations. In these kinds of scenarios Caching comes to rescue in-terms of improving performance by avoiding expensive operations like database calls or web service calls to fetch the commonly used or rather static data (which doesn't change more often) that needs to be displayed on to the UI. In IBM BPM, there is beautiful option for this called jsCache.
How jsCache works? 
jsCache stores data server side as mutli-level javascript Map (Key-value pair), with the first level being the name of the cache and map of the values to be stored corresponding to that cache name. Each data key in a given cache can be associated with an expiry time (optional though), so that the cached data can be refreshed at regular intervals of time. Figure 1 helps illustrate the storage of data in jsCache,

Figure 1: illustration of jsCache
You can download the jsCache.js file  by clicking here.

Wednesday, April 1, 2015

IBM BPM Coach Validation with Multiple Buttons

In this post, I would like discuss about an issue with Coach Validation when there are multiple button validations available in a single Coach and possible solution for the same.

First let me describe the issue.
I have a coach which has three buttons, Button1, Button2, Button3. On click of each button, field validation should happen for the fields corresponding to each button. you can go through my other post related to UI Validation to understand on how to do validation in IBM BPM.
In the below image, 'tick' mark for each transaction (line) indicates that validation should be performed on click of that particular button. Unfortunately, even though validations has to be performed for multiple buttons, all the validations should be handled in a single Validation Script (you can notice in the Figure 1 that there is only one validation Script). In order to validate the fields corresponding a button, we need to identify which button is clicked up on. To identify the button clicked up on, we can bind a Boolean variable to each button  as shown in Figure 2 and on click of the button, the bound variable will be set to true.  In the validation Script, we can verify this button variable (Boolean) and if true, then validate the corresponding fields for a particular button.
Figure 1