IBM Support

How to make comments required for a task step response

Technical Blog Post


Abstract

How to make comments required for a task step response

Body

Hello Community member! Here's an early holiday present for you! I hope you like it. 

How many times have you heard the requirement to capture a comment when a user chooses to complete a work item with a particular response? For example, if a work item is Rejected, you must enter a comment that will be part of the case history.

With IBM Case Manager 5.1 and its enhanced widget events, this is now possible without having to write a bunch of custom widgets. Let's have a look how.

Let's say we have a set of responses for a particular step of a task.

When the user clicks the Complete Survey response we will just do the normal thing and complete and return to the in-basket.

If they click the Need More Details response, the requirements say that we must capture a case comment that explains the user's decision.

The first thing we need to do is disable the standard broadcast events that are fired when you click the buttons in the work item toolbar. These broadcasted events are "shouted out" for all to hear with the Command widget being the ICM one that is listening for it. In ICM, we use broadcast events as a way to make the standard widgets work together without requiring any manual wiring. In ICM 5.1, you can now disable the broadcast and then wire the widgets up manually, allowing you to potentially alter the default behavior.

  • Go into edit mode on your Work Details page and show the widget settings for the Work Item Toolbar.

  • Click the checkbox to disable the broadcasting of the Complete Work Item event

The Complete Work Item event will get called for both the standard Complete button if your work item has no responses as well as for any response button that replaces it. The event payload tells you which button was clicked.

  • Display the Hidden Widgets area by clicking the item below the orange Edit Page link
  • Drag a new Script Adapter widget into the Hidden Widgets area
  • You may want to the use the Script Adapter's menu to Rename it to something unique. This is helpful when your page contains multiple Script Adapters
  • Choose the Widget Wiring command from the Script Adapter's settings menu
  • Wiring the incoming event to the Work Item Toolbar's Complete Work Item event
  • Wire the outgoing event to the Command widget's Complete Work Item event

The payload passed into the Script Adapter from the Work Item Toolbar's Complete Work Item event looks like this:

  {"getNext":false,"responseName":"Need More Details","stepName":"Initial Site Survey","workObjectNumber":"A63C4FB737D763439C689E5FEB4341CB","caseFolderId":"{0B496E4F-99C6-44E6-89E9-EBCBB5E6520E}"}
  • Display the Script Adapter's Setting dialog
  • Paste in the following javascript text. The code uses the environment variables described in this tip so it is completely portable with the exception of the Response name
  var caseID = payload.caseFolderId;    // The case ID in the payload has curly quotes around it that we need to remove    caseID = caseID.substr(1,caseID.length-2);       var note = "";          if (payload.responseName != "Need More Details")                     return payload;                 else if (note = prompt("Please enter a reason for this response:"))              {             var serverBase = window.location.protocol + "\/\/" + window.location.host;     var feedURL = this.iContext.io.rewriteURI(serverBase + "/CaseManager/CASEREST/v1/case/" + caseID+ "/comments?TargetObjectStore="+ecmwdgt.getBean("spaceConfig").getTargetOS()+ "&CommentType=case");                       var comment= {"CommentType":"Case","CommentContext":102,"CommentText": note};                               var xhrArgs = {              		url: feedURL,              		postData: dojo.toJson(comment),              	        handleAs: "json",              		headers: { "Content-Type": "application/json"},                              load: function(data){                              } ,                                            error: function(error)                              {                                  alert ("Oops..." + error);                              }                            		};                 dojo.xhrPost(xhrArgs);                 return payload;              }
  • Now when the user clicks the Need More Details button, they will see the following:

  • If they click cancel on the prompt dialog, the event is not passed on and they will remain on the page
  • If they enter a reason and click OK, the step will complete and a new comment will be added to the case

[{"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

ibm11281208