Saturday, July 6, 2019

IBM FileNet Case Manager Script adapter

Set New Case Default Values when create new case

Pages > Add Case > Add Script Adapter widget > make it hidden > edit wiring

"Page Container " : "SendNewCaseInfo" > "Receive event payload"




window.myPayload = payload;
window.solutionPrefix= this.solution.getPrefix();

var editable = myPayload.caseEditable;
alert(editable);
if(editable != null){
require(['icm/model/properties/controller/ControllerManager'],
function(ControllerManager) {
var collectionController = ControllerManager.bind(editable);
collectionController.beginChangeSet();

//Get Current User Name
var PortEmployeeName = ecm.model.desktop.userDisplayName;

//Set as default value for textbox PortEmployeeName
collectionController.getPropertyController(solutionPrefix + '_PortEmployeeName').set('value',PortEmployeeName);

collectionController.endChangeSet();
ControllerManager.unbind(editable);
});
}


Show Hide field based on another field value 


var solution = this.solution;
var prefix = solution.getPrefix();

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


  workItem = payload.workItemEditable;
  this.collectionController = ControllerManager.bind(workItem);


  this.collectionController.getPropertyController(prefix+"_PROJECTMILESTONDATES").watch("value", function(value){
      if (value === "1"){
        collectionController.getPropertyController(prefix+"_REVIEWUSERS").set("hidden", true);
      } else {
        collectionController.getPropertyController(prefix+"_REVIEWUSERS").set("hidden", false);
      }
  });


});



Add button beside textbox 

search for textbox that has placeholder = "project_name" and add button beside it



dojo.query("input[placeholder='project_name']").forEach(function(item)
    {
              item.offsetParent.offsetParent.insertAdjacentHTML('beforeend', "<input type=button value=? class=btn >");
    });


Add Case Custom validation before save

  • // Add a Script Adapter to your Add Case page and hide it
  • // Wire the incoming event for the Script Adapter from the Page Container's Send New Case Information event
var coord = payload.coordination;
var caseEdit = payload.caseEditable;
var solution = this.solution;
var prefix = solution.getPrefix();

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

if(coord){

/*Participate in the VALIDATE coordination step*/

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

if(context[Constants.CoordContext.CASE]){

   /*Check work item property attribute's value*/

   var propId = prefix + '_Description';

   /*Retrieve prop value(s) using property controller API*/

   var theController = ControllerManager.bind(caseEdit);
   var propController = theController.getPropertyController(propId);
   var value = propController.get("value");

   /*Unbind is necessary to prevent mem leak.*/

   ControllerManager.unbind(caseEdit);

   if(value === null || value === undefined || value === ""){

      /*Abort the page completion with passing a message to user*/

      abort({"message":"Please enter a description before adding the case."});
   }else{
      complete();
   }
 }else{
    complete();
 }
 });
}
});


Workitem data validation
based on which step response is selected


  • Add a Script Adaptor 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 Adaptor's Receive Event.
  • The additional data validation logic will be triggered when the appropriate response button is clicked.
var coord = payload.coordination;
var workitemEdit = payload.workItemEditable;
var solution = this.solution;
var prefix = solution.getPrefix();

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 specific response, an empty string ("") stands for the Complete button*/

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

   /*Check work item property attribute's value*/

   var propId = prefix + '_Description';

   /*Retrieve prop value using property controller API*/

   var theController = ControllerManager.bind(workitemEdit);
   var propController = theController.getPropertyController(propId);
   var value = propController.get("value");

   /*Unbind is necessary to prevent mem leak.*/

   ControllerManager.unbind(workitemEdit);

   if(value === null || value === undefined || value === ""){

      /*Abort the workitem completion with passing a message to user*/

      abort({"message":"Please enter a description before sending for investigation."});
   }else{
      complete();
   }
 }else{
    complete();
 }
 });
}
});








Hiding Attachment widget based on some property

//var coord = payload.coordination;
//var caseEdit = payload.caseEditable;
//var solution = this.solution;
//var prefix = solution.getPrefix();

if (payload.eventName === "icm.SendWorkItem" )
{

var coordination = payload.coordination;
                     
var workEdit = payload.workItemEditable;

                 
if(workEdit.icmWorkItem.stepName === "Request for PreSubmission Meeting")
    {         

require(["icm/model/properties/controller/ControllerManager", "icm/base/Constants","ecm/model/Repository"],function(ControllerManager, Constants,repository)
            {         
                coordination.participate(Constants.CoordTopic.AFTERLOADWIDGET, function(context, complete, abort)
                {
                                     
                    var collectionController = ControllerManager.bind(workEdit);
                    var Controller = collectionController.getPropertyController("CPA_VarHideAttachment"); // CPA_VarHideAttachment Case property
                 
                    var HideAttachment = Controller.get("value");
         
                    if(HideAttachment == "Yes")
                    {
                    dojo.query("span").forEach(function(item)
                        {
                            if(item.innerHTML==="Attachments")
                                {
                                    var prnt = item.parentNode.parentNode.parentNode.parentNode.parentNode;
                                    prnt.style.display = "none";
                                }
                        });
                    }
                        complete();
             
                });
             
                /* Use the AFTERLOADWIDGET coordination topic handler to release the controller binding for the editable. */
                /* Since the prop controller can be shared, doing this in the AFTERLOADWIDGET ensures no other widget overrides your changes. */
             
                coordination.participate(Constants.CoordTopic.AFTERLOADWIDGET, function(context, complete, abort) {
                    /* Release the controller binding for the editable. */
                    ControllerManager.unbind(workEdit);
                 
                    /* Call the coordination completion method. */
                    complete();
                });
            });
    }

}









Open Case Details after Add Case


Pages > Add Case > Add Script Adapter widget > make it hidden > edit wiring

"Page Container " : "SendNewCaseInfo" > "Receive event payload"




And, put the following code in it. 
The script hook to the AFTERSAVE coordination topic, it will be executed after case is saved.






/**
 * Created by tianxj on 2014/3/28.

 */

console.log("Open new case begin");

var self = this;

self.caseEdt = payload.caseEditable;

console.log(self.caseEdt);



var coord = payload.coordination;



require(["icm/base/Constants", "icm/util/Coordination"], function(Constants, Coordination){

    console.log("part to aftersave");

    console.log(Constants.CoordTopic.AFTERSAVE);

    console.log(coord);

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

        console.log("part call back");

        self.checkCount = 0;

        self.statusChecker = setInterval(function(){

            self.caseEdt.retrieveAttributes(function(){

                self.checkCount++;

                console.log("check case states");

                console.log(self.checkCount);

                var caseState = self.caseEdt.caseObject.attributes["CmAcmCaseState"];

                console.log(caseState);

                if(caseState == 2){

                    clearInterval(self.statusChecker);

                    delete self.statusChecker;

                    self.onBroadcastEvent("icm.OpenCase",{
                        "caseEditable": self.caseEdt,
                        "coordination": new Coordination()
                    });
                    console.log("Open the case");
                    setTimeout(complete,1000);
                }

                if(self.checkCount > 5){
                    console.log("Can't open the case");
                    clearInterval(self.statusChecker);
                    delete self.statusChecker;
                    abort({"message":"Case was created, but can't open it according to wrong case status"});
                }
            });
        }, 1000);
    });
});
console.log("Open new case end");

============


Open Work Task After Create a Case

//"Page Container " : "SendNewCaseInfo" > "Receive event payload"


var self = this;
var coord = payload.coordination;

require(["icm/base/Constants", "icm/util/Coordination"],
    function (Constants, Coordination) {

        console.log("Open new case begin");

        self.caseEdt = payload.caseEditable;

        var workListName = "Investigator";

        console.log("part to aftersave");
        console.log(Constants.CoordTopic.AFTERSAVE);
        console.log(coord);

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

            debugger;
            //Entered Form Info
            console.log("part call back");
            self.checkCount = 0;
            self.caseCreatedFlag = false;
            self.statusChecker = setInterval(function () {

                self.caseEdt.retrieveAttributes(function () {

                    self.checkCount++;
                    console.log("check case states");
                    console.log("checkCount :" + self.checkCount);
                    var caseState = self.caseEdt.caseObject.attributes["CmAcmCaseState"];

                    console.log("caseState : " + caseState);
                    //Working (2) // Completed (3)
                    if (caseState == 2 && !self.caseCreatedFlag) {

                        self.caseCreatedFlag = true;
                        clearInterval(self.statusChecker);
                        delete self.statusChecker;

                        var caseUniqueField = self.caseEdt.caseObject.attributes["CmAcmCaseIdentifier"];
                        subsVar = {
                            "substitution_vars": [{
                                "name": "CmAcmCaseIdentifier",
                                "value": [caseUniqueField],
                                "type": "xs:string"
                            }]
                        };

                        
                        function retrieveAttributes(myItemFull) {
                            console.log("Inside Retrieve Attributes");
                            myEdit = myItemFull.createEditable();
                            payload = {};
                            payload.workItemEditable = myEdit;
                            payload.coordination = new icm.util.Coordination();
                            payload.UIState = new dojo.Stateful();
                            payload.openInNewTab = false;
                            broadcastResult = self.onBroadcastEvent(
                                "icm.OpenWorkItem", payload);
                            console.log(broadcastResult);
                            setTimeout(complete, 1000);
                        }
                        var workitem;
                        function retrieveWorkItem(payload) {

                            console.log("Retrieve Work Item");
                            workitem = payload;
                            retrieveWorkItemFlag = false;
                            // Search for the specific workItem
                            console.log("Found " + workitem.fetchCount + " item(s) in the work basket");
                            for (var i = 0; i < workitem.fetchCount; i++) {
                                retrieveWorkItemFlag = true;
                                myItem = icm.model.WorkItem.fromWorkItem(workitem.getItem(i));
                                myItem.lockStep(retrieveAttributes);
                                //systemResponseDialogHelper.hideLoadingIndicator();
                                return;
                                
                            }
                            console.log("Could not find Step, Retrying in 1 second");
                            if (!retrieveWorkItemFlag) {
                                setTimeout(function () {
                                    // Check here as well as this was not tested
                                    selectedWorkList.retrieveWorkItems(
                                        retrieveWorkItem, null,
                                        false, true, null,
                                        "(CmAcmCaseIdentifier=:A)",
                                        subsVar, null);
                                }, 1000);
                            }
                        }

                        function retrieveWorkList(payload) {
                            console.log("Retrieve Work List");
                            debugger;
                            worklist = payload;
                            if (worklist != null) {
                                for (var i = 0; i < worklist.length; i++) {
                                    debugger;
                                    console.log("Work List Name: " + worklist[i].auth_name);
                                    if (worklist[i].auth_name == workListName) {
                                        selectedWorkList = worklist[i];
                                        //systemResponseDialogHelper.showLoadingIndicator();
                                        selectedWorkList.retrieveWorkItems(
                                            retrieveWorkItem,
                                            null, false,
                                            true, null,
                                            "(CmAcmCaseIdentifier=:A)",
                                            subsVar, null);
                                        break;
                                    }
                                }
                                console.log("End of WorkList Search");
                            } else {
                                console.warn("No Worklist Found");
                            }
                        }
                        self.getRole().retrieveWorklists(retrieveWorkList);
                    }



                    if (self.checkCount > 5 && !self.caseCreatedFlag) {

                        console.log("Can't open the case");

                        clearInterval(self.statusChecker);

                        delete self.statusChecker;

                        abort({ "message": "Case Created. Please close this tab and find the case in your in-basket." });

                    }

                });

            }, 2500);


        });

    });

console.log("Open new case end");





Create custom in basket filter 
to show only works that has property "PortEmployeeName" equal the current active user


1) Configure script adapter wiring

2) Configure In-basket to wait for custom filter

3) Configure user Role to pass filter property

add property PortEmployeeName to the role



4) Script adapter code

var caseFilterValue = ecm.model.desktop.userDisplayName; 
var dataType = "xs:string";
var solutionPrefix = ecm.model.desktop.currentSolution.prefix;
var inbasketName = ecm.model.desktop.currentRole.name;
var queueName = solutionPrefix + "_" + inbasketName.replace(/\s+/g, '');

var json = {"queueName":queueName,
"inbasketName":inbasketName,
"hideFilterUI":true,
"queryFilter":"("+solutionPrefix+"_PortEmployeeName = :A)",
"queryFields": [{"name": solutionPrefix+"_PortEmployeeName", "value": caseFilterValue , "type": dataType}],
"hideLockedByOther":"false"};

var dynamicFilter = icm.model.InbasketDynamicFilter.fromJSON(json);
var dynamicFilters = [];
dynamicFilters.push(dynamicFilter);
var applyFilters = {"dynamicFilters": dynamicFilters};
return applyFilters; 


=================



How to get next Work item without showing the work items list?

Pages > Work details







How to access user information from an ICM page script?

Using the current user id, name, or role is a great way to provide more user centric information to you case workers. In IBM Case Manager 5.2 and it new client side scripting model, here's how you get that information.

Add a script adapter widget to the Cases solution page
Wire its incoming event to a custom event action button added to the toolbar of one of the page widgets
var userName = ecm.model.desktop.userDisplayName;
var userId = ecm.model.desktop.userId;
var role = ecm.model.desktop.currentRole.name;

var messageDialog = new ecm.widget.dialog.MessageDialog({
    text: "<b>Role</b>: " + role + " - " + userName + " - " + userId
});
messageDialog.show();

Get Next work item in custom page
By default, you will see all the work item list and can choose anyone to process, 
But custom service in bank or insurance company should not choose a favorite custom to service; they just service for any custom the system push to them.
To achieve this, first, we need to hidden In-basket, which can be easily done by hidden default Work page.
Open target solution, switch to Roles tab, click to open target role, then on Pages tab, remove Work page.


var self = this;
var role = ecm.model.desktop.currentRole;   /* self.role; */
require(["icm/model/WorkItem","icm/util/WorkItemHandler"],function(WorkItem, WorkItemHandler)
{
 role.retrieveWorklists(function(inbaskets)
 {
  if(inbaskets.length > 0)
  { 
/*if there are multiple In-baskets*/
    var inbasket = inbaskets[0]; /*we choose the first one, this should be first role's In-basket*/
    inbasket.retrieveWorkItems(function(resultSet)
{
     var items = resultSet.getItems();  
     /*fetch the work items in this In-basket*/
     if(resultSet.getItems().length >0)
{  
/*if there are multiple work items*/
var first = resultSet.getItems()[0];  
/*get the first one*/
first = WorkItem.fromWorkItem(first);  
    debugger;
/*this is to change an ICN work item to the format of ICM work item*/
var workItemHandler = new WorkItemHandler(self);  
/*open it*/
workItemHandler.handleCurrentPageWorkItem(first);  
/*process the next first work item*/                                 
}
    });
  }
 });
});


=======
Read cases from another solution

Key points:
icm/model/_DesktopMixin
this.retrieveSolutions(function(solutionList) 

---------------------
define(["dojo/_base/declare", 
"dojo/_base/lang",
"dojo/_base/array",
"icm/base/Constants",
"icm/model/Case",   
"ecm/LoggerMixin",
"icm/model/_DesktopMixin"], 
function(declare, lang, array, Constants, Case, LoggerMixin, _DesktopMixin){
    return declare("icm.custom.pgwidget.customSearchWidget.CustomWidgetContentPaneEventListener", [LoggerMixin, _DesktopMixin], {

        searchTemplate: null,
        widget: null,

        constructor: function(widget){
            this.widget = widget;
        },

        buildPayload: function(values) {
            if(!values) {
                console.log("An invalid values is received!");
                return;
            }

            console.log("retrieveSolutions");
            var that = this;
            this.retrieveSolutions(function(solutionList) {
                array.forEach(solutionList, function(solution) {
                    if (solution.id === "CBFPSFED_57_2") {
                        console.log("CBFPSFED_57_2");

                        var searchPayload = new icm.util.SearchPayload();

                        var params = {};
                        params.ObjectStore = solution.getTargetOS().id;

                        params.ceQuery = "SELECT t.[FolderName], t.[LastModifier], t.[DateLastModified], t.[CmAcmCaseTypeFolder], t.[CmAcmCaseState], t.[CmAcmCaseIdentifier], t.[DateCreated], t.[Creator], t.[Id], t.[ContainerType], t.[LockToken], t.[LockTimeout],  t.[ClassDescription], t.[DateLastModified], t.[FolderName] FROM [CmAcmCaseFolder] t where ";
                        params.ceQuery += "t.[CmAcmCaseIdentifier] LIKE '%%'  AND t.[JR572_name] LIKE '%%%'";

                        solution.retrieveCaseTypes(function(types) {
                            console.log(types);             
                            console.log(params.ceQuery);
                            params.caseType = types && types.length > 0 && types[0].name; // default to the first case type
                            params.solution = solution;

                            searchPayload.setModel(params);
                            var payload = searchPayload.getSearchPayload(function(payload) {
                                that.widget.onBroadcastEvent("icm.SearchCases", payload);
                                console.log("buildPayload");
                                console.log(payload);
                            });
                        });
                    }
                });
            });
        },

        _eoc_: null
    });
});





======
How do I programmatically start a discretionary task from a toolbar button?




var caseEditable = this.getActionContext("Case")[0];
var solution = caseEditable.caseObject.caseType.getSolution();
var prefix = solution.getPrefix();
var theCaseID = caseEditable.getCaseTitle();

/* Modify this line to match the internal name of a task in your solution */
var taskType = prefix + "_MeetingRequest";

callback=function(taskEditable){

/* Modify this line to set the task name that appears in the Task List. It can be anything you want  */
     taskEditable.setTaskName("Meeting Re: " + theCaseID);

     var addTaskPagePayload = {
          "taskEditable": taskEditable,
          "coordination": new icm.util.Coordination()
     };
     this.broadcastEvent("icm.AddTask", addTaskPagePayload);
};
caseEditable.caseObject.createNewTaskEditable(taskType, dojo.hitch(this,callback));













Custom Dropdown List 

  • Wire a Script Adaptor to the icm.SendNewTaskInfo event from container.
var theProp = this.solution.getPrefix() +"_CaseStage";

console.log("Registering choice function");

/* For the add task payload, the workItemEditable is returned by the getLaunchStep method */

var workItemEdt = payload.taskEditable.getLaunchStep();
var coord = payload.coordination;

var choices = [{
    label: "Triaging",
    value: "1"
}, {
    label: "Processing",
    value: "2"
}, {
    label: "Finalizing",
    value: "3"
}];

require(["icm/model/properties/controller/ControllerManager", "icm/base/Constants"],function(ControllerManager, Constants){
    coord.participate(Constants.CoordTopic.LOADWIDGET, function(context, complete, abort){
        var propsController = ControllerManager.bind(workItemEdt);
        var propController = propsController.getPropertyController(theProp);
        if (propController){
            propController.set("choices", choices);
        }
        else
            console.log("ERROR - No such property: " + theProp);        
        complete();
    });

   /* Use the AFTERLOADWIDGET coordination topic handler to release the controller binding for the editable. */
   /* Since the prop controller can be shared, doing this in the AFTERLOADWIDGET ensures no other widget overrides your changes. */
   coord.participate(Constants.CoordTopic.AFTERLOADWIDGET, function(context, complete, abort) {
      /* Release the controller binding for the editable. */
      ControllerManager.unbind(editable);

      /* Call the coordination completion method. */
      complete();
   });

});






======
for more information visit ECM Community Blog


http://ecmibm.blogspot.com/2016/09/dynamic-web-application-development.html