This article describes how one can keep track of comments which have been entered into one or more forms during the NetIQ User Application request process. This is helpful if you want to display a ‘running commentary’ of the previously entered comments on each new form when it is presented to the User.

Implementation

For instance, during the request process, the business logic might require that a User enters some comments detailing why the request was made. When the request is submitted, there may well be a two-step approval with an approval form being routed to the Manager of the requestor and another approval form being routed to the Service Desk group which, in turn, requires two approvals. Assume we have the following actors in the request process:

  • The requestor is User A
  • The Manager of the requestor is User B
  • The 1st Service Desk User is User X
  • The 2nd Service Desk User is User Y

By using the code contained within this article, you can expect the following outcome:

  • User A submits a request via a form which includes a mandatory comments field
  • User B opens the approval form and sees the comments which were entered in by User A. User B approves the request
  • User X opens the Service Desk approval form and sees the comments entered in by both User A and User B. User X approves the request
  • User Y opens the Service Desk approval form and sees the comments entered in by User A, User B, and User X. User Y denies the request
  • Since the request process has finished (User Y denied the request), an email is sent to User A and User B
  • Within the email, there is a HTML table which displays all the comments entered during the request life-cycle (including their own). User A and User B would be able to see that the request was denied, the time the request was denied, by whom the request was denied, and the reason for the denial

In order to implement such a solution, the first thing that is required is to add a data-mapping activity after each of the forms for which you want to collect a comment. The source for the data mapping is shown below. The result of the data-mapping is stored in the flowdata variable Global/values/FinalComments. In the code below, the form where the comments have been captured is Activity15.

function returnMe()
    {
        var varCommentsArray = new Packages.java.util.ArrayList();
        var varComments = new Packages.java.util.ArrayList();
        var varDelimiter = flowdata.get('Global/values/ProcessID');
        var varDate = new Date();
        var varActorType = 'Manager'
        var varAction = 'APPROVED'
        varCommentsArray = flowdata.getObject('Global/values/FinalComments');
        var varTimeStamp = varDate.toString();
        var varActorName = IDVault.get('Activity15.getAddressee().toString()', 'Employee', 'FullName');
        var varDetails = flowdata.get('Activity15/approval_form/fldFormComments').toString();
        varComments = returnComments(varActorType, varAction, varActorName, varDetails, varTimeStamp, varDelimiter, varCommentsArray);
        return varComments;
    }
returnMe();

The returnComments function, called from the above function, is shown below.

function returnComments(varActorType, varAction, varActorName, varDetails, varTimeStamp, varDelimiter, varCommentsArray)
    {
        var varDate = new Date();
        var varTimeStamp = varDate.toString();
        var varComponents = varTimeStamp + varDelimiter + varActorType + varDelimiter + varAction + varDelimiter + varActorName + varDelimiter + varDetails;
        varCommentsArray.add(varComponents);
        return varCommentsArray;
    }

The code below is used to display the comments in a HTML field. The code can be used either in a pre data-mapping activity for a HTML field on a form, or as part of the HTML email template. Because there is only a single function to construct the table, the displayed data on the form and in the email looks identical, colours and all.

function buildCommentsTable(varCommentsArray, varCommentsArraySize, varHtmlStart, varHtmlEnd, varDelimiter)
    {
    var varString = varHtmlStart;
    for (i=0;i < varCommentsArraySize;i++)
        {
            var varComponent = varCommentsArray.get(i).getFirstChild().getNodeValue();
            varComponentArray = varComponent.split(varDelimiter);
            varString = varString + "<tr>";
            for (j=0;j < varComponentArray.length;j++)
                {
                    varString = varString + "<td>";
                    varString = varString + varComponentArray[j].toString();
                    varString = varString + "</td>";
                }
            varString = varString + "</tr>";
        }
    varString = varString + varHtmlEnd;
    return varString;
    }