I got a requirement to make a history form for a workflow. For that, I had to fetch the data from a task list. We can use Rest API, SP Services, or any other methods for this kind of task. So, I chose REST API for the same. Now, the question is, what will be the scenario? Because Workflow status columns of Assign to and Modified Date are not available in the normal list. Then, I learned that we can fetch it from the task list or history list, because all the workflow information resides there.
History list
History List is the hidden list which consists of all the details of workflow and it also consists of GUID of list and workflow ID also. With the help of the following URL, we can access the History List.
http://[servername]/[sitename]/lists/Workflow%20History
You have to change [server name] & site name from your tenant. Here we will fetch the data from Task List.
In this history form, I need to display Assign Date, Request id, assigned to, and some other columns
So, first of all, create a custom list, as per the required columns, such as Request no., Employee Name, Start Date, End Date, 1st Manager Name, 2nd Manager Name etc.
- Employee Name: Single Line Text.
- Start Date: Date and time Type.
- End Date: Date and Time Type.
- 1st Manager: People and Group Type.
- 2nd Manager Name: People and Group Type.
After that, you have to make a workflow. You can make approval workflow with a condition using "Start approval workflow". In which you can take multiple approvers as per your requirement. You can take “Start Approval Process” Approval Workflow for this.
For fetching the data, you can take Rest API or SP Services or other methods. You can perform basic operations like Create, Update, Delete using GET or POST methods. To get an item, you can use GET Method and to give any value or to post any value, you can use POST Method. For Rest API, you don’t need to attach any other SharePoint library or Client assemblies for performing these operations. You can use Rest endpoints.
Now, the code is given below for fetching the data from the task list.
- <script type="text/javascript">
- $(document).ready(function() {
- getDatafromWFTaskList();
- });
-
- function getDatafromWFTaskList() {
- var serverURL = _spPageContextInfo.webAbsoluteUrl;
- $.ajax({
- url: serverURL + "/_api/web/lists/Getbytitle('Tasks')/items?$filter=ID eq 91&$expand=Author,AssignedTo&$select=ID,Author/Title,Created,WorkflowOutcome,AssignedTo/Title,
- type: "GET",
- headers: {
- "Accept": "application/json;odata=verbose;"
- },
- success: function(data) {
- var count = data.d.results.length;
- for (var i = 0; i < count; i++) {
- var RequestID = data.d.results[i].ID;
-
- $('#RequestID').html(RequestID);
- var InitiatedBy = data.d.results[i].Author.Title;
- $("#InitiatedBy").html(InitiatedBy);
- alert(InitiatedBy);
- var Initiated = data.d.results[i].Created;
- $("#Initiated").html(Initiated);
-
- var CurrentStatus = data.d.results[i].WorkflowOutcome;
- $("#CurrentStatus").html(CurrentStatus);
- var AssignedTo = data.d.results[i].AssignedTo.Title;
- $("#AssignTo").html(AssignedTo);
-
- var AssignDate = data.d.results[i].Created;
- $("#AssignDate").html(AssignDate);
- }
- },
- error: function(data) {
- console.log("error details: " + data);
- },
- });
- }
- </script>
-
- <body>
- <div id="IntiateHistory">
- <h2>Initiation History</h2>
- <table>
- <tr>
- <td><label>Request ID : </label> <label id="RequestID"></label></td>
- <td> </td>
- <td><label>Initiated By : </label> <label id="InitiatedBy"></label></td>
- </tr>
- <tr>
- <td><label>Initiated : </label> <label id="Initiated"></label></td>
- <td> </td>
- <td><label>Current Status : </label> <label id="CurrentStatus"></label></td>
- </tr>
- </table>
- </div>
- <div id="ReviewHistory">
- <h2>Review History</h2>
- <table>
- <tr>
- <td><label>AssignTo : </label> <label id="AssignTo"></label></td>
- <td> </td>
- <td><label>AssignDate : </label>
- <td> <label id="AssignDate"></label></td> </td>
- </tr> table> </div>
- <div id="Buttons"> </div>
- </body>
-
- </html>
The output is given below. It doesn’t consist of CSS or designing part much. So, you can also design it as per as your requirement. Here, the date format is not ISO, so you can also change your date format as per as your requirement.
This will be the output which consists of two parts - Initiation History & Review History.