How to get workflow template id programmatically using JavaScript Object Model (jsom) in SharePoint

This SharePoint workflow tutorial explains, how to get a workflow template id programmatically using the javascript object model (jsom) in SharePoint Online or SharePoint 2013/2016.

Workflows are an integral part of SharePoint. We can use workflows to automate various business processes in SharePoint 2013 or SharePoint Online. We can develop workflows using a browser, SharePoint designer or by using visual studio 2015/2017/2019.

If you are new to SharePoint Online workflow development, you can check out my previous workflow tutorials:

We can develop two types of workflows:

  • List workflow: These workflows will be attached to SharePoint online list or document libraries.
  • Site workflow: This workflow is not for any specific list or library, these will be available for sites.

Here in this SharePoint workflow tutorial, we will discuss how we can get workflow template id programmatically using JavaScript Object model (jsom). Here we have developed one site workflow using visual studio 2015 as a SharePoint hosted add-in and we have attached to the host website.

SharePoint get workflow template id programmatically using jsom

I have added a simple button and on click of that, it will display the workflow id. You can add the below code inside a script editor web part inside a web part page in SharePoint online site.

Here we have the workflow name as “TestWorkflow” and through the below code we can retrieve the workflow id from SharePoint online site.

<input type="button" id="btnSubmit" value="Get Workflow ID" /><br/>
<script src=""></script>
$(function () {
function bindButtonClick() {
$("#btnSubmit").on("click", function () {
function getWorkflowId() {
var clientContext = new SP.ClientContext.get_current();
this.workflows = clientContext.get_web().get_workflowAssociations();
clientContext.executeQueryAsync(Function.createDelegate(this, this.onQuerySucceeded), Function.createDelegate(this, this.onQueryFailed));
function onQuerySucceeded(sender, args) {
var enumerator = this.workflows.getEnumerator();
var workflow = enumerator.get_current();
if(workflow.get_name() == "TestWorkflow")
function onQueryFailed(sender, args) {

You may like following jsom SharePoint tutorials:

This is how we can get the SharePoint 2013 workflow template id using jsom. Hope this will be helpful.