This SharePoint workflow tutorial, we will discuss how to get workflow template id using the javascript object model (jsom) in SharePoint 2013/2016 or SharePoint Online?
Workflows are very useful in SharePoint. We can automate the business process using Workflows in SharePoint 2013 or SharePoint Online. We can develop a workflow using out of box feature like browser, SharePoint 2013 designer or we can develop workflow by using visual studio 2015. Once developed and deployed a workflow, we can attach to a list or library or we can use a site workflow.
If a workflow is attached to a SharePoint online or SharePoint 2013 list, we can retrieve workflow template id from a list using JavaScript object model code (jsom).
Here we have a list in our SharePoint online site and various workflows are attached to the list. By using the below code we are going to retrieve the id of the workflow whose name is “Archiving”.
JSOM Code to get workflow template id in SharePoint Online/2013
In this particular example, I have added the below code inside a script editor web part which I have added inside a web part page in SharePoint Online.
<input type="button" id="btnSubmit" value="Get Workflow ID" /><br/>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script>
<script>
$(function () {
bindButtonClick();
});
function bindButtonClick() {
$("#btnSubmit").on("click", function () {
getWorkflowId();
});
}
function getWorkflowId() {
SP.SOD.executeFunc("sp.js", "SP.ClientContext", function () {
SP.SOD.registerSod('sp.workflowservices.js', SP.Utilities.Utility.getLayoutsPageUrl('sp.workflowservices.js'));
SP.SOD.executeFunc('sp.workflowservices.js', "SP.WorkflowServices.WorkflowServicesManager", function () {
context = SP.ClientContext.get_current();
web = context.get_web();
workflowServicesManager = new SP.WorkflowServices.WorkflowServicesManager(context, web);
var subs = workflowServicesManager.getWorkflowSubscriptionService().enumerateSubscriptionsByList('4C384857-8AEF-484E-8163-FED3592E15A4');
context.load(subs);
context.executeQueryAsync(function () {
var subEnumerator = subs.getEnumerator();
while (subEnumerator.moveNext()) {
var sub = subEnumerator.get_current();
if (sub.get_name() == 'Archiving') {
var templateId = 'Workflow id: '+sub.get_id();
alert(templateId)
return;
}
}
},
function (sender, args) {
alert(args.get_message());
});
});
});
}
</script>
Once you Save the code and click on the button, it will display the workflow id inside an alert box like below:
You may like following SharePoint workflow tutorials:
- Start a task process SharePoint designer 2013 workflow action
- Copy Document SharePoint Designer 2013 Workflow Action
- Collect Signature Workflow in SharePoint Online
- SharePoint designer workflow: Create Laptop Request Approval Workflow
- SharePoint designer 2013 Workflow: Assign task to group using Assign a task workflow action
- SharePoint Designer 2013 Workflow: Do Calculation Action Example
- SharePoint Designer Workflow Declare item as record
- This computer is part of a farm error while uninstalling workflow manager 1.0 in SharePoint 2016/2013
- SharePoint Designer 2013 Workflow: Create List Item Action with Example
I hope this tutorial will be helpful to get workflow template id using jsom (JavaScript object model) in SharePoint Online.
I am Bijay from Odisha, India. Currently working in my own venture TSInfo Technologies in Bangalore, India. I am Microsoft Office Servers and Services (SharePoint) MVP (5 times). I works in SharePoint 2016/2013/2010, SharePoint Online Office 365 etc. Check out My MVP Profile.. I also run popular SharePoint web site EnjoySharePoint.com