KBEC-00091 - Listing nested job steps data in email notifications

Article ID:360033194331
2 minute readKnowledge base

Summary

Html_JobTempl.txt (located with other email notification templates in src/samples/notifier) is a job notifier that creates an email with overall job information, as well as step-specific data.
One caveat: for a given job, it displays the very top set of steps only. Therefore it will not be very useful if you have multiple nested subprocedure calls.

Solution

Instead of listing job steps in a single call, create a function that calls itself recursively as it finds more subprocedure steps.

Examples

$[/javascript

    // Define a function that will expand the steps at the given level
    function expandSteps(steps, level) {

        var res = new String("");
        for (var stepName in steps) {

            var thisStep = steps[stepName];
            res += "    <tr>";
            res += "      <td class=\"success\">" + level + "</td>";
            res += "      <td class=\"success\">" + thisStep.name + "</td>";
            res += "      <td class=\"success\">" + thisStep.jobStepId + "</td>";
            res += "      <td class=\"success\">" + thisStep.status + "</td>";
            if ( thisStep.outcome == 'success' ) {
                res += "      <td class=\"success\">" + thisStep.outcome + "</td>";
            }
            else if ( thisStep.outcome == 'error' ) {
                res += "      <td class=\"error\">" + thisStep.outcome + "</td>";
            }
            else if ( thisStep.outcome == 'warning' ) {
                res += "      <td class=\"warning\">" + thisStep.outcome + "</td>";
            }
            else if ( ! thisStep.outcome ) {
                res += "      <td class=\"success\">" + "-" + "</td>";
            }
            res += "      <td class=\"success\">" + thisStep.errorCode + "</td>";
            res += "      <td class=\"success\">" + thisStep.procedureStep.stepName + "</td>";
            res += "      <td class=\"success\">" + thisStep.start + "</td>";
            res += "      <td class=\"success\">" + thisStep.finish + "</td>";
            res += "      <td class=\"success\">" + thisStep.subprocedure + "</td>";
            res += "      <td class=\"success\">" + thisStep.logFileName + "</td>";
            res += "    </tr>";

            //  Expand substeps recursively
            if (thisStep.steps) {
                res += expandSteps(thisStep.steps, level+1);
            }
        }
        return (res);
    }

    var res = new String("");
      res += "<table cellspacing=\"1\">";
      res += "    <tr class=\"header\">";
      res += "      <td>Job Step Level</td>";
      res += "      <td>Job Step Name</td>";
      res += "      <td>Job Step Id</td>";
      res += "      <td>Status</td>";
      res += "      <td>Outcome</td>";
      res += "      <td>Error Code</td>";
      res += "      <td>Proc Step</td>";
      res += "      <td>Start</td>";
      res += "      <td>Finish</td>";
      res += "      <td>Subprocedure</td>";
      res += "      <td>Log File Name</td>";
      res += "    </tr>";

    res += expandSteps(myJob.steps, 1);
    res;

]