1

I'm building a custom workflow history page which shows the history of workflow steps that we're executed (much the same like the original wrkstat.aspx page). The reason why I'm building it, is because of the automatic deletion of the references after 30 days (SharePoint Online) and users won't be able to access the workflow history anymore.

I already succeeded in displaying the workflow steps in a nice table, however I also would like to show the corresponding tasks. I can't seem to find the linking pin between the workflow history list and the task list. I know there is a field 'Related Content' (internal name: WorkflowLink), but I was hoping there would be WorkflowInstanceId field.

So far this is my code to display the workflow history and it's working fine:

<script type="text/javascript" src="/SiteAssets/jquery-1.11.3.min.js"></script>
<script type="text/javascript" src="/SiteAssets/jquery.SPServices-2014.02.min.js"></script>
<script>

$(document).ready(function() {
    //fetch instanceId from URL
    var wrkflowId = GetUrlKeyValue("InstanceId", false);

    var CamlQuery = '<Query><Where><Eq><FieldRef Name="WorkflowInstance" /><Value Type="Text">' + wrkflowId + '</Value></Eq></Where></Query>';
    var CamlViewFields = '<ViewFields><FieldRef Name="Description" /><FieldRef Name="User" /><FieldRef Name="Occurred" /><FieldRef Name="Event" /></ViewFields>';

    $().SPServices({
        operation: "GetListItems",
        async: false,
        listName: "Testflow History",
        CAMLViewFields: CamlViewFields,
        CAMLQuery: CamlQuery,
        completefunc: function (xData, Status) {
          $(xData.responseXML).SPFilterNode("z:row").each(function() {
                var wfDescription = $(this).attr("ows_Description");
                var wfUser = $(this).attr("ows_User");
                var wfOccured = $(this).attr("ows_Occurred");
                var wfEvent = $(this).attr("ows_Event");
                //remove all chars before # in the returned username
                wfUser = wfUser.split("#").pop();

                var eventType = wfEvent;
                switch (eventType) {
                    case "0":
                        wfEvent = "None";
                        break;
                    case "1":
                        wfEvent = "Workflow Started";
                        break;
                    case "2":
                        wfEvent = "Workflow Completed";
                        break;
                    case "3":
                        wfEvent = "Workflow Cancelled";
                        break;
                    case "4":
                        wfEvent = "Workflow Deleted";
                        break;
                    case "5":
                        wfEvent = "Task Created";
                        break;
                    case "6":
                        wfEvent = "Task Completed";
                        break;  
                    case "7":
                        wfEvent = "Task Modified";
                        break;
                    case "8":
                        wfEvent = "Task Rolled Back";
                        break;
                    case "9":
                        wfEvent = "Task Deleted";
                        break;
                    case "10":
                        wfEvent = "Error";
                        break;
                    case "11":
                        wfEvent = "Comment";
                        break;
                    default:
                        wfEvent = "None";
                }

                AddRowToTable(wfDescription,wfUser,wfOccured,wfEvent);
          });
        }
    }); 

    function AddRowToTable(wfDescription,wfUser,wfOccured,wfEvent)
    {
        $("#resultsTable").append("<tr class='ms-viewheadertr' valign='top'>" +                                 
                                "<td class='ms-vb2'>" + wfOccured + "</td>" +
                                "<td class='ms-vb2'>" + wfEvent + "</td>" +
                                "<td class='ms-vb2'>" + wfUser + "</td>" +
                                "<td class='ms-vb2'>" + wfDescription + "</td>" +                                
                               "</tr>");

    }


});
</script>
<div id="results">
    <table width="100%" class="ms-listviewtable" border="0" cellpadding="1" id="resultsTable">
        <tr class='ms-viewheadertr' valign='top'>
            <th class='ms-headerCellStyleNormal ms-vh2' scope='col'>Date Occurred</th>
            <th class='ms-headerCellStyleNormal ms-vh2' scope='col'>Event Type</th>
            <th class='ms-headerCellStyleNormal ms-vh2' scope='col'>User ID</th>
            <th class='ms-headerCellStyleNormal ms-vh2' scope='col'>Description</th>
        </tr>

    </table>
</div>

Hopefully someone can help me out on this.

Thanks! Kevin

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.