Monday, 15 July 2013

Adding a column to the InBasket grid in 9.3

I'm not sure how many times people have asked if it is possible to modify the InBasket to show different columns.

It must be enough since Aras are putting a configurable InBasket into release 9.4 at some time.

I had a look and found one way of adding your own additional columns to the InBasket.

In the InBasket.html file (found under the Innovator install directory Innovator/Client/Scripts/Inbasket) there is a function:

function populateActivityGrid()

This is the key function as it retrieves the current Activities for the logged on user and then formats them into the grid for display.
The method "top.aras.getAssignedTasks(...)" retrieves the tasks for the individual as formatted XML appropriate for creating a grid.

I decided it would be feasible to intercept the return from this method and insert additional information into the grid before displaying it to the user.
In this case I have added the "effective_date" field as the "Go Live Date"

function populateActivityGrid()
    {
      updateCurrentViewMode();
      emptygrid();
      var showWorkflow = 0;
      var showProject = 0;
      var showAction = 0;
      var saveArray = new Array();
      if (document.getElementById("wfl_act").checked) showWorkflow = 1;
      if (document.getElementById("project_act").checked)
        showProject = 1;
      else if (!ProjectSolutionLoadedInDB())
        showProject = -1;
      if (document.getElementById("action_items").checked) showAction = 1;
      saveArray.push(showWorkflow, showProject, showAction, currViewMode);
      top.aras.setPreferenceItemProperties("Core_GlobalLayout", null, { core_in_basket_history: saveArray.join("|") });

      if (currViewMode != "" && (showWorkflow == 1 || showProject == 1 || showAction == 1))

      {
          var tasks = top.aras.getAssignedTasks(currViewMode, showWorkflow, showProject, showAction);
          

          //******************************************************************************************

          // Brian Pye - Modified to add additional column for Go Live Date (effective_date) for changes.
          //******************************************************************************************
          // tasks is formatted xml.
          var taskXML = top.aras.createXMLDocument();
          taskXML.loadXML(tasks);

          //var thead = taskXML.selectSingleNode("//thead");

          var newHead = taskXML.createElement("th");
          newHead.appendChild(taskXML.createCDATASection("Go Live Date"));

          taskXML.childNodes[0].selectSingleNode("//thead").insertBefore(newHead, taskXML.selectSingleNode("//thead").childNodes[6]);

          var newCol = taskXML.createElement("column");
          newCol.setAttribute("width", "80");
          newCol.setAttribute("edit", "NOEDIT");
          newCol.setAttribute("align", "middle");
          newCol.setAttribute("sort", "DATE");
          newCol.setAttribute("inputformat", "d/MM/yyyy");
          newCol.setAttribute("locale", "en-AU");
          newCol.setAttribute("BGINVERT", "false");
          newCol.setAttribute("TEXTCOLORINVERT", "true");
          
          taskXML.childNodes[0].selectSingleNode("//columns").insertBefore(newCol,taskXML.selectSingleNode("//columns").childNodes[6]);


          var rows = taskXML.selectNodes("//tr");

          var inn = new top.Innovator();


          for (var i = 0; i < rows.length; i++) {

              var attID = taskXML.selectNodes("//tr")[i].selectSingleNode("./userdata[@key='attachedId']").getAttribute("value");
              var attTypeId = taskXML.selectNodes("//tr")[i].selectSingleNode("./userdata[@key='attachedTypeId']").getAttribute("value");

              var itm = inn.newItem();

              itm.setAttribute("typeId", attTypeId);
              itm.setID(attID);
              itm.setAttribute("select", "effectivity_date");
              itm.setAction("get");
              itm = itm.apply();

              var dteNode = "";

              if (itm.isError()) {
                  dteNode = taskXML.createElement("td");
              } else {
                  var effDate = itm.getProperty("effectivity_date", "");
                  dteNode = taskXML.createElement("td");
                  dteNode.appendChild(taskXML.createCDATASection(effDate));
              }

              taskXML.childNodes[0].selectNodes("//tr")[i].insertBefore(dteNode, taskXML.selectNodes("//tr")[i].childNodes[6]);

              

          }



          grid.initXML(taskXML.xml);

          //******************************************************************************************
          // end inserted code - Brian Pye
          //******************************************************************************************


        //grid.initXML(tasks);   // comment this out - BP

        grid.setSelectedRow(selRowId, false);
        updateControlsState(getSelectedRowID());
      }
      else
      {
        emptygrid();
        updateControlsState(getSelectedRowID());
        return;
      }
    }


I have used the IDs returned from the getAssignedTasks to then retrieve additional information from the server.
Since this is a change to an Aras html file you will have to keep this in mind when you move to a new version or go through an upgrade process.

This is not the most efficient way of doing things but provided your user doesn't have hundreds of tasks it doesn't have much impact on performance and allows you to add another column.