IBM Support

Export Case List to CSV File with Script Actions

Technical Blog Post


Abstract

Export Case List to CSV File with Script Actions

Body

Hello everyone!

 

Here's another fun IBM Case Manager client scripting customization that is really easy, but super helpful for some solutions.

IBM Content Navigator has a nice built in feature to allow users to export the content of a displayed list to a .csv file which is compatible with your favourite spreadsheet, Wouldn't it be nice if you could do the same thing with the ICM Case List?

 

image

 

ICM Case Builder lets you create toolbar buttons or menu items that execute some script that you enter. Your script is called with a payload that includes context for the action itself and the page widget it belongs to. For this example, we are going to add an Export toolbar button to the Case List widget by opening the Cases page (or whichever page you have your Case List on) and clicking the widget settings icon (the gear) and going to the Toolbar tab.

 

image

 

Once there, add a new toolbar button and set its Action to Script Action then enter the following JavaScript.

   
  function download(filename, text) {
  var element = document.createElement('a');
  element.setAttribute('href', 'data:text/plain;charset=utf-8,' + encodeURIComponent(text));
  element.setAttribute('download', filename);
  element.style.display = 'none';
  document.body.appendChild(element);
  element.click();
  document.body.removeChild(element);
  }

 

  var self = this;
  var resultSet = self.widget.ecmContentList.getResultSet();
  var exportText = "";
     
  /* Use this to show the internal property names
  for (i = 0; i < resultSet.columnNames.length; i++) {
  exportText += resultSet.columnNames[i] + ",";
  }
  */
  for (i = 0; i < resultSet.columnNames.length; i++) {
  exportText += resultSet.structure.cells[0][i].name + ",";
  }
  exportText += "\r";

 

  for (i = 0; i < resultSet.items.length; i++) {
  var caseItem = resultSet.items[i];
  for (j = 0; j < resultSet.columnNames.length; j++) {
  exportText += caseItem.getValue(resultSet.columnNames[j]) + ",";
  }
  exportText += "\r";
  }  download(self.widget.solution.name + ".csv", exportText);

 

 

That's it! Save and deploy your solution and go to your case list and find a few cases to export. Click your new toolbar button and Ta Da! You will have a nice .csv file waiting for you in your downloads folder.

The majority of this script uses the ICN JS API since most ICM widgets are built on components provided my the Navigator framework. Have al look and see what else you do to make your ICM solutions great.

 

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

ibm11280818