IBM Support

How to retrieve Case Tasks information in current Case using JavaScript API

Technical Blog Post


Abstract

How to retrieve Case Tasks information in current Case using JavaScript API

Body

In many scenario we may require to retrieve tasks information within the current case. We can use ICM_Operations but it requires a component step in workflow hence user has to complete the step. ICM JavaScript API provides searchTasks() function, with the concrete implementation of this function we can retrieve most of the information of the tasks, based on result set we can perform validation, completion etc.. set of operations.

Below sample code is written in a Script Adapter widget and describes searching all running Tasks in the current case and performs a simple validation. Using full set of proper parameters, we can retrieve required information as per need.

  

  • Add a Script Adapter widget to the hidden widgets area on a work details page
  • Wire an inbound event from the Page Container's Send Work Item to the Script Adapter's Receive Event.
  • Retrieve the tasks and validation logic will be triggered when the appropriate response button is clicked.

 

var coord = payload.coordination;
var workitemEdit = payload.workItemEditable;
var myCase = payload.workItemEditable.getCase();
console.log("myCase ---"+myCase);
var solution = this.solution;
var prefix = solution.getPrefix();

var numOfTasks;

require(["icm/base/Constants", "icm/model/properties/controller/ControllerManager"], function(Constants, ControllerManager){

if(coord){

/*Participate in the VALIDATE cordination step*/

coord.participate(Constants.CoordTopic.VALIDATE, function(context, complete, abort){

/* Check the response  "Complete Project" */

if(context[Constants.CoordContext.WKITEMRESPONSE] === "Complete Project"){

//searchTasks Parameters
var taskTypes="";
var properties=[];
var propertyFilter="([TaskState]=4)";  //Tasks are in Working state
var resultsDisplay={};
var includeHidden= false;

callback=function(task)  //callback function
{
     console.log("task----" +task);
     var tasks=task;
     numOfTasks=tasks.length;
console.log("numOfTasks----" +numOfTasks);

/* Check numOfTasks in Working state, I need to check if more than one task is in Working state */ 

   if(numOfTasks > 1 ){
  
  if (confirm("Few tasks are in progress for this Project. Sure to Complete Project?") == true) {
        complete();
    } else {
        abort({silent:true});
    }
   }else{
      complete();
   }

};
 
myCase.searchTasks(taskTypes,properties,propertyFilter,resultsDisplay,includeHidden,dojo.hitch(this,callback));

 }else{
    complete();
 }
 });
}
});

return payload;

 

Note:

Referenece - IBM developerWorks, IBM Knowledge Center ICM JavaScript API documentation.

 

Regards,

Ramesh Bhat

[{"Business Unit":{"code":"BU053","label":"Cloud & Data Platform"},"Product":{"code":"SSCTJ4","label":"IBM Case Manager"},"Component":"","Platform":[{"code":"PF025","label":"Platform Independent"}],"Version":"","Edition":"","Line of Business":{"code":"LOB45","label":"Automation"}}]

UID

ibm11280854