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.

Karsten Pohnke About Karsten Pohnke
He is Consultant for SharePoint Solutions for collaboration, communication and business processes. He provides his customers applications based on standard features as well as development or combining the power of several microsoft tools like Dynamics CRM. In his free time he tries to collect tipps and worthy experience in this blog.