Get TemplateID for starting a workflow from the ribbon in SharePoint 2013 workflow

Today I tried to get the TemplateID for starting a workflow from the ribbon in SharePoint 2013 workflow.

Some Background

To start a workflow from a SharePoint ribbon a URL needs to be build up in the following format:

[code lang=text]
SPUserCustomAction action = web.Lists[listname].UserCustomActions.Add();

string workflowTemplateId = workflowId.ToString();

action.Title = title;

action.ImageUrl = “/_layouts/15/images/wfComment.png”;

action.Url = “{SiteUrl}/wfsvc/06f8de2413bc41fe869414fc061435f9/WFInitForm.aspx?List={ListId}&ID={SelectedItemId}&TemplateID={“+ workflowTemplateId +”}&WF4=1&Source={Source}”;

action.Location = “CommandUI.Ribbon.ListView”;

action.Sequence = 0;

action.CommandUIExtension =

“”+

“”+

” ” +

” +

” Command=’WF.AddComment’ ” +

” Image32by32=’/_layouts/15/images/wfComment48x48.png’ ” +

” Image16by16=’/_layouts/15/images/wfComment32x32.png’ ” +

” Sequence=’0′ ” +

” LabelText=’Add Comment’ ” +

” Description=’Add Comment Button’ ” +

” TemplateAlias=’o1′ />” +

” ” +

” ” +

” ” +

” +

” CommandAction=’~site/wfsvc/06f8de2413bc41fe869414fc061435f9/WFInitForm.aspx?List={ListId}&ID={SelectedItemId}&TemplateID={” + workflowTemplateId + “}&WF4=1&Source={Source}’ />” +

” ” +

“”;

action.Update();
[/code]

The problem:

The problem however is how do we get the TemplateID all the other bits of the URL can be resolved with variables that are filled in dynamically but the Template ID is a bit trickier.

[code lang=text]
‘~site/wfsvc/06f8de2413bc41fe869414fc061435f9/WFInitForm.aspx?List={ListId}&ID={SelectedItemId}&TemplateID={” + workflowTemplateId + “}&WF4=1&Source={Source}’
[/code]

The Solution:

[code lang=text]
var clientContext = new ClientContext(web.Url);
var workflowServiceManager = new WorkflowServicesManager(clientContext, clientContext.Web);

WorkflowSubscriptionService workflowSubscriptionService = workflowServiceManager.GetWorkflowSubscriptionService();

var workflowSubscriptions = workflowSubscriptionService.EnumerateSubscriptions();

clientContext.Load(workflowSubscriptions);

clientContext.ExecuteQuery();

foreach(var workflowSubscription inworkflowSubscriptions)

{

workflowTemplateId = workflowSubScription.Id

}
[/code]


Discover more from SharePains

Subscribe to get the latest posts sent to your email.

Avatar of Pieter Veenstra

Is your business still running on paper trails, sprawling Excel files, or ageing Access databases? There's a better way — and I can show you exactly what it looks like. I'm the Technical Director of Vantage 365, a Microsoft solutions consultancy working with clients across the UK, the Netherlands, and worldwide. For over 30 years I've been turning messy, manual business processes into clean, automated systems that save time, reduce errors, and give teams the visibility they need to make better decisions. SharePains is not just any blog run by a Microsoft MVP. Have you ever used Try-Catch in Power Automate? The original post about Try-Catch in Power Automate can still be found on this site, https://sharepains.com/2018/02/07/try-catch-finally-in-power-automate-flow/ Or have you ever used the Pieter’s method to avoid variables and speed up your flows? https://sharepains.com/2020/03/11/pieters-method-for-advanced-in-flows/ You can contact me using contact@sharepains.com

Related Posts

5 thoughts on “Get TemplateID for starting a workflow from the ribbon in SharePoint 2013 workflow

  1. Hi Pieter,

    Thanks for shared, but can you help me!

    This code is in .net?

    How can I use this in JSOM, can you shared some information.

    I need start a workflow 2010 in a Onpremise SharePoint 2013 with JSOM and Sharepoint Designer.

    Tks,

    Leonardo Brito

    From – São Paulo – Brasil

  2. Hi Pieter,

    I need to start the 2010 workflow by sharepoint designer 2013 with a rest call.

    I’m trying to do this in different ways, like:

    _api/SP.WorkflowServices.WorkflowInstanceService.Current/StartWorkflow(item=’143′, templateId='{33451e59-3b82-428f-932f-224a2cadadc5}’,workflowParameters=”)

    _api/SP.WorkflowServices.WorkflowInstanceService.Current/StartWorkflow(‘143’, ‘{33451e59-3b82-428f-932f-224a2cadadc5}’, ”)

    _api/SP.WorkflowServices.WorkflowInstanceService.Current/StartWorkflow(associationName=’testesendmailnovofluxopermissao’,null, listId='{E4B87BDC-E524-4DBA-8AA6-28DAA9701E63}’, itemGuid='{C9D55D81-5D01-4AC9-9FAE-EA1D90087015}’)

    _api/SP.WorkflowServices.WorkflowInstanceService.Current/StartWorkflow(‘testesendmailnovofluxopermissao’, ‘{E4B87BDC-E524-4DBA-8AA6-28DAA9701E63}’, ‘{C9D55D81-5D01-4AC9-9FAE-EA1D90087015}’)

    _api/SP.WorkflowServices.WorkflowInstanceService.Current/StartWorkflow(associationName=”testesendmailnovofluxopermissao’,correlationId=’null’,listId='{E4B87BDC-E524-4DBA-8AA6-28DAA9701E63}’, itemGuid=’143′, workflowParameters=”)

    **** But don’t work, don’t start the workflow 2010.

    I created successfully in JSOM, but I really need to start the flow 2010 via sharepoint designer 2013.

    1. I don;’t understand how you want to start a workflow in SharePoint Designer? SharePoint designer is used to develop workflows not to run workflows. They are run from within SharePoint.

  3. Thank you Pieter!
    You’re right, I can just call the action 2010 start workflow

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Discover more from SharePains

Subscribe now to keep reading and get access to the full archive.

Continue reading