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]

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

  1. commented on April 8, 2020 by Leonardo Brito

    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

    • commented on April 8, 2020 by Pieter Veenstra

      Hi Leonardo,

      Where do you want the user to start the workflow from?

      What should trigger the flow? In the example the workflow is started from the ribbon.

  2. commented on April 9, 2020 by Leonardo da Silva Brito

    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.

    • commented on April 9, 2020 by Pieter Veenstra

      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. commented on April 9, 2020 by Leonardo da Silva Brito

    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.

%d bloggers like this: