I have workflow history oob list which store workflow history data in workflow history parent instance id, workflow template id, workflow association id, listid.... Fields.
I want to retrieve workflow details like workflow name by workflow instance id which is stored as I mentioned in above SharePoint Online OOB list. How to achieve that?
Thanks in advance
Common api for workflow instance service.
<script type="text/javascript" src="/_layouts/15/sp.runtime.js"></script>
<script type="text/javascript" src="/_layouts/15/sp.js"></script>
<script type="text/javascript" src="/_layouts/15/sp.workflowservices.js"></script>
<script type="text/javascript">
function RetrieveWorkflowInstances() {
var context = SP.ClientContext.get_current();
var web = context.get_web();
var workflowServicesManager = new SP.WorkflowServices.WorkflowServicesManager(context, web);
//var workflowDeploymentService = workflowServicesManager.getWorkflowDeploymentService();
var workflowInstanceService = workflowServicesManager.getWorkflowInstanceService();
//6a899d24-4813-4920-9e61-cdaa2cfe1b3a
var specificInstance = workflowInstanceService.getInstance("6a899d24-4813-4920-9e61-cdaa2cfe1b3a");
context.load(specificInstance);
context.executeQueryAsync(function (sender, args) {
console.log(specificInstance);
}, function (sender, args) {
alert('Request failed. ' + args.get_message() + '\n' + args.get_stackTrace());
});
// get all instances
var workflowInstances = workflowInstanceService.enumerateInstancesForListItem("7B96090E-FDAD-4075-B24A-21686AE255B4", 1);
context.load(workflowInstances);
context.executeQueryAsync(function (sender, args) {
// enumerateDefinition returns ClientCollection object
var definitionsEnum = workflowInstances.getEnumerator();
// Going through the definitions
while (definitionsEnum.moveNext()) {
var def = definitionsEnum.get_current();
// Displaying information about this definition - DisplayName and Id
console.log("id: " + def.get_id() + " Status: " + def.get_status() + " Stage: " + def.get_userStatus());
}
}, function (sender, args) {
alert('Request failed. ' + args.get_message() + '\n' + args.get_stackTrace());
});
}
</script>
<input id="Button1" onclick="RetrieveWorkflowInstances()" type="button" value="button" />