Wednesday, January 27, 2016

Accessing Case Information from within ICM Case Manager Widget Code

Requirement:
                ICM Case Manager widget developers often find the need to access Solution and/or Case information and its artifacts, to be able to make decisions and act upon them.
Solution:
               The solution involves accessing the cache object of the workItem object which gets passed onto a widget. From the cache object we can extract various artifacts like case ID, case name, Solution prefix, case properties and so on …
Sample Code:
// summary:
// Handler for receiving the event icm.SendWorkItem.
// payload: The received payload.
handleICM_SendWorkItemEvent: function(payload){
 if(!payload){
  console.log(" payload not received, returning");
  return;
 }
 console.log("Entering handleICM_SendWorkItemEvent ");
 
 // Defining a callback function 
 var callback = function(workitem) {

 var caseObject = workitem.getCase();
 if (caseObject != null) {
  caseObject.retrieveAttributes(lang.hitch(this, function(caseObj) {
  // get Case ID from case object
  var caseId = caseObj.caseIdentifier; 
      
  /* get CaseType object from case Editable. 
     This caseTypeObject has information about the 
     specific case type (and its artifacts) within a solution
  */
  var caseEditable = caseObj.createEditable()
  var caseTypeObject = caseEditable.getCaseType(); 
      
  // get Case Type name from caseTypeObject
  var caseType = caseTypeObject.name;
      
  // get solution prefix from caseTypeObject
  var prefix = caseTypeObject.solution.prefix;
      
  /* get Case properties using provider, symbolicName.Here provider 
     is F_CaseFolder which is the location where all 
     Case properties are saved.
  */
  var customerId=caseEditable.getProperty("F_CaseFolder",
      prefix+"_CustomerID").value;
     
  this.randomMethod(caseEditable, caseType, prefix, customerId);
  }));
 }
 };
 
 if (payload.workItemEditable) {
   payload.workItemEditable.
  retrieveCachedAttributes(lang.hitch(this, callback));
 }

}

Widgets can handle events like receiving case information, workitem and so on.
The above example code shows the method which handles one such event (SendWorkItemEvent). Callback and dojo functions are used to get the necessary information. Code has inline comments explaining things in detail.

No comments:

Post a Comment