SharePoint 2010 get workflow template id by using Javascript

Just a small post, but maybe it helps you. In my case i had a subsite as workspace. This subsite contains a site workflow. I inserted a modal dialog on the start page which opens the initial form for this workflow.

If a user creates a new subsites based on the template for this workspace, the site workflow gets a new template id, which is necessary for the link of the modal dialog. So my idea was to create a javascript function which get the template id of the site workflow dynamically and adds it to the modal dialog. Well what should i tell you – if it does not work, i would not have written this post.

I look for the site workflow by name. If you know any better solution i would like to hear from you. So here is the code is used. [sourcecode languag=”csharp”]

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() == “My Site Workflowname”)

function onQueryFailed(sender, args) {


There are so many possibilites with the client object model and javascript which might be interesting.


The article or information provided here represents completely my own personal view & thought. It is recommended to test the content or scripts of the site in the lab, before making use in the production environment & use it completely at your own risk. The articles, scripts, suggestions or tricks published on the site are provided AS-IS with no warranties or guarantees and confers no rights.

About Karsten Schneider 312 Articles
Consultant for Microsoft 365 Applications with a strong focus in Teams, SharePoint Online, OneDrive for Business as well as PowerPlatform with PowerApps, Flow and PowerBI. I provide Workshops for Governance & Security in Office 365 and Development of Solutions in the area of Collaboration and Teamwork based on Microsoft 365 and Azure Cloud Solutions. In his free time he tries to collect tipps and worthy experience in this blog.