BPM, Workflow, and Case

BPM, Workflow, and Case

Come for answers. Stay for best practices. All we’re missing is you.

 View Only

IBM Case Manager - Add comment in case history on work item response click 

2 days ago

IBM Advanced Case Manager:

Environment: ICM 5.2.x / ICM 5.3.x

When user clicks a response button on Work Details Page in ICM Client a CUSTOM audit history has to be created along with User Name, time stamp and user custom multiline message in the case history tab. Following are the steps:

BM Case Manager Builder- Edit specific Work Details Page

1. Add new hidden script adaptor

2. Edit script adaptor setting and put the code

3. Add event wiring- Page Container->send work item->ScriptAdaptorName->RecieveEventPayload

4. commit and Deploy solution

Note: Please change response name and properties to your own environment. :

console.log("RAGBAT RAGBAT");
console.log("Payload started");
console.log("Payload: ", payload);

var coord = payload.coordination;
var workitemEdit = payload.workItemEditable;
var solution = this.solution;

var currentCase = workitemEdit.getCase();
 
        
require(["icm/base/Constants", "dojo/_base/lang", "dojo/on", "ecm/model/Desktop", "icm/action/case/CaseAction"],
function(Constants, lang, on, Desktop, CaseAction) {

    payload.coordination.participate("COMMIT", lang.hitch(this, function(context, complete, abort) {

        try {

            
            if (context[Constants.CoordContext.WKITEMRESPONSE] !== "Denied") {
                complete();
                return; 
            }

            console.log("Showing custom Work Item comment input dialog");

            var overlay = document.createElement("div");
            overlay.style.position = "fixed";
            overlay.style.top = "0";
            overlay.style.left = "0";
            overlay.style.width = "100%";
            overlay.style.height = "100%";
            overlay.style.backgroundColor = "rgba(0, 0, 0, 0.3)"; 
            overlay.style.zIndex = "9998";  
            document.body.appendChild(overlay);
            
            
            var dlg = document.createElement("div");
            dlg.style.position = "fixed";
            dlg.style.top = "30%";
            dlg.style.left = "35%";
            dlg.style.width = "350px";
            dlg.style.padding = "15px";
            dlg.style.background = "white";
            dlg.style.border = "1px solid #444";
            dlg.style.zIndex = "9999";
            dlg.style.boxShadow = "0px 0px 10px rgba(0,0,0,0.4)";

            var label = document.createElement("div");
            label.innerHTML = "Enter your comment:";
            dlg.appendChild(label);

            var textArea = document.createElement("textarea");
            textArea.style.width = "100%";
            textArea.style.height = "120px";
            textArea.style.marginTop = "8px";
            textArea.style.resize = "none";
            dlg.appendChild(textArea);

            var errorLabel = document.createElement("div");
            errorLabel.style.color = "red";
            errorLabel.style.display = "none";  
            errorLabel.innerHTML = "Comment is required.";
            dlg.appendChild(errorLabel);
            
            var btnOk = document.createElement("button");
            btnOk.innerHTML = "OK";
            btnOk.style.marginRight = "10px";

            var btnCancel = document.createElement("button");
            btnCancel.innerHTML = "Cancel";

            dlg.appendChild(btnOk);
            dlg.appendChild(btnCancel);
            document.body.appendChild(dlg);

           
            btnOk.onclick = function() {

                var commentText = textArea.value.trim();

                if (!commentText) {
                    errorLabel.style.display = "block";  
                    return;  
                }

              
                errorLabel.style.display = "none";

               
                var userName = Desktop.userDisplayName;
                var timestamp = new Date().toLocaleString();
                var finalComment = "[" + userName + " - " + timestamp + "]\n" + commentText;

                console.log("Preparing to add comment to case:", finalComment);

    
    
    
            currentCase.addCaseComment(102,finalComment,function onReady(){
            console.log("comment was set");
            document.body.removeChild(dlg);
            document.body.removeChild(overlay);
            complete();
            },function onFailure(){
            console.error("could not create case comment");
            document.body.removeChild(dlg);
            document.body.removeChild(overlay);
            abort();
            },true);

            
                
                
                
                
                
                
            };

            
            btnCancel.onclick = function() {
                console.log("User canceled the comment dialog.");
                document.body.removeChild(dlg);
                document.body.removeChild(overlay);
                abort({silent:true});
            };

        } catch (e) {
            console.log("Exception occurred:", e);
            alert(e);
            abort();
        }

    }));

});

return payload;

Statistics
0 Favorited
4 Views
1 Files
0 Shares
1 Downloads
Attachment(s)
txt file
ICMCustomScript.txt   4 KB   1 version
Uploaded - Tue November 11, 2025
Add case history entry (user name, Date time and Custom message) on work item response click