How to create a button that starts a site workflow in O365?

  • 29 August 2017
  • 4 replies
  • 42 views

Userlevel 5
Badge +13

I've browsed a ton of threads on here about creating a button to start a list workflow, but not a site one in O365. When I go to the Site Workflows area and copy the URL of starting the workflow I want, I get this Javascript:

 

javascript:StartWorkflow4('26220e76-0c13-4c07-8763-4f51589b57cf', '', '')‍

 

I can't figure out how to basically build a URL or a button to start this darn site workflow. I am not looking to put this on a Nintex Form, just on the page.


4 replies

Userlevel 3
Badge +9

There may be a more elegant solution, but what about having the java script button create a List Item in a SharePoint list, which has a workflow on it to start the site workflow when a new item is created?

Userlevel 5
Badge +13

That could work, how would I go about implementing that?

Badge +7

Should be something like this (button starting site workflow) :

<script>
var dlg = null;
function startWorkflowYearlyArchive()
{
try
{
showInProgressDialog();
var ctx = SP.ClientContext.get_current();
var wfManager = SP.WorkflowServices.WorkflowServicesManager.newObject(ctx, ctx.get_web());
var subscription = wfManager.getWorkflowSubscriptionService().getSubscription("IDOFYOURWORKFLOW");
ctx.load(subscription, 'PropertyDefinitions');
ctx.executeQueryAsync(
function(sender, args)
{
wfManager.getWorkflowInstanceService().startWorkflow(subscription, "");
ctx.executeQueryAsync(
function(sender, args)
{
closeInProgressDialog();
},
function (sender, args)
{
closeInProgressDialog();
alert(errorMessage);
});
});
}
catch(ex)
{
alert(ex);
dlg.close();
}
}
function closeInProgressDialog()
{
if(dlg != null)
{
dlg.close();
}
}
function showInProgressDialog()
{
if(dlg == null)
{
dlg = SP.UI.ModalDialog.showWaitScreenWithNoClose("Waiting...", "Shouldn't take long", null, null);
}
}
</script>
<p>
<a onClick="javascript:startWorkflowYearlyArchive()" style="cursor: pointer;">MESSAGE</a>
</p>

Userlevel 5
Badge +13

Hey Thomas, thanks for your reply! I'm not great with Javascript, can you point out where in your code I need to set my own parameters (workflow name, etc)?

Reply