• Entries (RSS)
  • Comments (RSS)

Querying human task based on custom property using EJB API

Posted by | Posted in Websphere Process Server / Integration Developer | Posted on 22-08-2008

Tagged Under : , , , , ,

My last post talked about setting a custom attribute for a human task. Today I will be talking about querying the human task using EJB API based on the custom attribute. The complete code for querying the human task based on custom property is given below.

javax.naming.Context ctx = new javax.naming.InitialContext();
	Object result = ctx.lookup("com/ibm/task/api/HumanTaskManagerHome");
    com.ibm.task.api.HumanTaskManagerHome home = (com.ibm.task.api.HumanTaskManagerHome) javax.rmi.PortableRemoteObject.narrow(result,com.ibm.task.api.HumanTaskManagerHome.class);
    com.ibm.task.api.HumanTaskManager taskManager= home.create();
 
    com.ibm.task.api.QueryResultSet rst = taskManager.queryAll("TASK.TKIID","TASK_CPROP1.NAME='id' AND TASK_CPROP1.STRING_VALUE='1'", null,null,null,null);
 
 
    while(rst.next()){
    	System.out.println("Got Task ID "+rst.getString(1));
    }

In my code I have used the queryAll method for getting all the tasks for the user. The parameters for the queryAll method I used are, the select clause as the first parameter, where clause as the second parameter. Since I was selecting only Task Id, I used TASK.TKIID as my select clause. In the where clause TASK_CPROP1.NAME specifies the name of the custom attribute. For me the custom attribute name was id and TASK_CPROP1.STRING_VALUE specifies the value we are expecting for the custom property. When I created the task I entered 1 as the value for Id. The above query would return you the tasks with custom property name id and value 1.

WebSphere Process Server Human task custom properties

Posted by | Posted in Websphere Process Server / Integration Developer | Posted on 20-08-2008

Tagged Under : , , , , ,

Have you ever come across a situation where you want to get a specific task instance based on some input data? For eg, if you have an order task, you may want to retrieve the human task based on the order Id. The order Id will be part of the business object and will be available only if you have the human task. When we querying the human task we cannot retrieve human task based on the value of business object associated with it. So to get a task instance with some order Id, it’s not a good solution to get the entire human task and loop through each task to check whether it matches with the order Id we have.

To address this issue WebSphere Process Server and WebSphere Integration Developer provides a nice solution of using custom properties. In WPS and WID you can attach a custom property while creating a human task and it is possible to retrieve the human task based on custom property value.

In today’s post I will be explaining how to create a custom property for a human task. For this I have created a simple Business Object called CustomBO. This will be the business object associated with our human task. My Business object looks like the one shown in the figure.

The interface used in my business process is

Create a human task using the interface we created in the previous step. Once you have created the human task click on properties window and click on Environment.

Click on Add to add a new custom property.

Enter the name for your custom property. The value of the custom property needs to come from the business object. So we will be using a replacement expression as the value from the custom property.

Now click on Ok.

You are done with creating a custom property for a human task.

To run this using BPC Explorer, add your human task to a business process and assemble it in the assembly diagram.

Launch your BPC explorer. Go to processes and start the business process. While starting the business process I entered 1 as the value for my id. Now to view this custom property value in your human task click on ‘My To-dos’ and find out the task we just created. Click on the task and go to the details page. Click on custom properties tab you can see the custom property with the values we specified.

I tried this example in WID 6.1 only. For users of WID 6.0.2 and lower versions, this method will not work (At least it was not working for me). For me in WID 6.0.2 after executing the process, the custom property value was the replacement expression itself. Ie, the replacement expression was not replaced by its value. I think it is because in WID 6.0.2 and lower versions the business object is available only after creating the human task. (Not sure its just a guess from me).

Anyways don’t worry I had used a nice workaround to fix this issue in WID 6.0.2, I created a escalation which will be executed after one second or so and from there reset the value of the custom properties. :-)