This is that function:
<script type="text/javascript">
var errorMessage = "Something went wrong. To try again, reload the page and then start the workflow.";
var theForm = document.formsm'aspnetForm'];
if (!theForm)
{
theForm = document.aspnetForm;
}
function StartWorkflow(iwa)
{
var elIwaStart = document.getElementById("iwaStart");
elIwaStart.value = iwa;
theForm.submit();
}
var dlg = null;
function StartWorkflow4(subscriptionId, itemId, itemGuid)
{
showInProgressDialog();
var ctx = SP.ClientContext.get_current();
var wfManager = SP.WorkflowServices.WorkflowServicesManager.newObject(ctx, ctx.get_web());
var subscription = wfManager.getWorkflowSubscriptionService().getSubscription(subscriptionId);
ctx.load(subscription, 'PropertyDefinitions');
ctx.executeQueryAsync(
function(sender, args)
{
var params = new Object();
var formData = subscription.get_propertyDefinitions()g"FormData"];
if(formData != null && formData != 'undefined' && formData != "")
{
var assocParams = formData.split(";#");
for(var i = 0; i < assocParams.length; i++)
{
paramsiassocParams] = subscription.get_propertyDefinitions()passocParams];
}
}
if(itemId)
{
wfManager.getWorkflowInstanceService().startWorkflowOnListItem(subscription, itemId, params);
}
else
{
wfManager.getWorkflowInstanceService().startWorkflow(subscription, params);
}
ctx.executeQueryAsync(
function(sender, args)
{
closeInProgressDialog();
var elWf4Start = document.getElementById("wf4Start");
elWf4Start.value = 1;
theForm.submit();
},
function (sender, args)
{
closeInProgressDialog();
alert(errorMessage);
}
);
},
function(sender, args)
{
closeInProgressDialog();
alert(errorMessage);
}
);
}
function closeInProgressDialog()
{
if(dlg != null)
{
dlg.close();
}
}
function showInProgressDialog()
{
if(dlg == null)
{
dlg = SP.UI.ModalDialog.showWaitScreenWithNoClose("Please wait...", "Waiting for workflow...", null, null);
}
}
function HandleCheckinBeforeStartWorkflow()
{
var strError = "Please check this document in before starting a workflow.";
window.alert(strError);
}
</script>
Though I posted the function, I tried using it as a javascript button on a form and I had a success message, but no workflow was started though I gave it the right parameters.
So I'm not sure yet how to use it on a Nintex Form. But that would be nice if we can
Hi Andrew,
Thanks for searching. I have the same result as you after putting this code in a Snippet in the view.
The line on which the javascript stops is
var wfManager = SP.WorkflowServices.WorkflowServicesManager.newObject(ctx, ctx.get_web());
Maybe because there is someting from the Nintex Workflow page that is missing in the form or in the view.
Best regards,
Christophe
I ran into the workflow template ID being dynamic as well. I was trying to use calculated fields to present a series of links to launch workflows. I ended up using a Nintex workflow to build the the hyperlinks and then adding them to a rich text field. Note that you can also modify the source parameter in the link so that when the workflow is done initializing, it will take you to an alternate location. I used this method to allow a user to open up a list item that uses a Nintex form. On the Nintex form, it has a list view of related items and the workflows links for those items. So when the user clicks a link, it runs the workflow and then returns them to the list item instead of dumping them back to the list parent list view.
I did some initial searching and didn't find an easy solution to the template ID issue. We've just settled on manually updating it if the workflow changes. The other solutions I saw seemed to involved programming.
Ben, you can change the "TemplateID=..." to WorkflowName=MyWorkflow
That way when you republish the workflow it will still point to it.
OK - that's just silly. In all of my searching, no mention of WorkflowName as a valid parameter! Thanks Gerard, my testing shows this works. Very helpful.
Kevin,
Sure, you will need SharePoint Designer to add the custom button. There you can create Custom Actions for any list/library. In the custom action you want the "Navigate to URL" option. Here you will put the URL to start either a list workflow or a site workflow. We've used both. The site workflow, when users don't have edit permission to a list/lib, which then calls the list/lib workflow for them.
The URL is structured as follows:
http://SP-site.com/_layouts/15/NintexWorkflow/StartWorkflow.aspx?WorkflowName=MyWorkflow
You will need an image to place in the ribbon that gets added to the custom action in two sizes; 32x32 and 16x16. These can be saved to one of the site asset libraries if you like.
Regards
Kevin,
Your javascript/workflow approach can work as long as the form you are in is not an "edit" form. IIRC workflows don't run on edited items until after the form has closed. If however, you're talking about an item being viewed, then this could work. You could initiate a list workflow from the current form that uses the itemID of the currently viewed item as an input parameter for the list workflow. It would be as if the user started the workflow from the item's (ECB) menu.
I'm not familiar with Nintex Forms so I don't know what the javascript limitations are. The javascript could build the URL as described above, incorporating the currently viewed item's itemID.
Hope this makes sense.
Kevin, you could do this in an alternate method. By simply creating a Choice field in the list of type radio button. Then select to display as a button in control settings. Then in the item workflow that starts on new or modified, it can check for a value in the new Choice field, when it is there it can then create a new item in any list with any of the available data in the form (current item). Or calculate to new values.
You may not need a javascript button to start a workflow, but have the same user experience with a choice field button. Just a thought to share in case it is of any use.
Just following up if any of these options helped to find a resolution.
I am getting the below error when I try to do the same
Error: Guid should contain 32 digits with 4 dashes (xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx). undefined
No Andrew. Nothing has helped me. However, when the script posted above by you was working pretty well with SPD workflows, but not with Nintex. I also posted my SPD working script in another similar question.
https://community.nintex.com/message/22533
Could you use a button that navigates to the url that is similar to
Site URL/_layouts/15/NintexWorkflow/StartWorkflow.aspx?List={List ID}&ID=ID&WorkflowName=MyWorkflow&Source=Item URL.
Kalyan, here's some detail on how to use this option.
The web URL is the first part: http://my.local.dom
This is followed by the reference to the start workflow aspx page (for Nintex in this case): /_layouts/15/NintexWorkflow/StartWorkflow.aspx
To reference the workflow name simply add: ?WorkflowName=MyWorkflow
So the complete URL looks like: http://my.local.dom/_layouts/15/NintexWorkflow/StartWorkflow.aspx?WorkflowName=MyWorkflow
If you want to add a source path that the page returns to when they start the workflow or click Cancel, you can add the following to the end:
&Source=http://my.local.dom/myhomepage.aspx
Hope this helps,
Gerard
Kaylan, Andrew points out the missing part in mine - "?List . . .&ID={ItemID}" for a list workflow. I must have pulled the method for a Site workflow not a list workflow. Once you provide the ListID & the ItemID you should be good.
I know this is an old thread, but I can't get this solution to work for me for a site workflow in Office 365.
My goal is simply to put a link or button on a SharePoint page that starts a site workflow; anyone have any tips or assistance? I've been searching on the community but I'm mostly finding either 2013 solutions (that won't work for me) or List solutions I've not been able to tailor.
Do you have a subscription yet? I've made seen buttons that start NWC workflows.
Hey Andrew, sorry if I wasn't clear, I'm trying to do this for a site workflow. Are you suggesting that I basically use a NWC workflow to do that, and have the button start the NWC Workflow?
hi there,
I can see there is a difference between people who are using HTML to program the button and people who just want to start the workflow by pushing a button on a webpage.
Does anyone know if you can start the workflow with a button (without having to learn / edit) HTML code?
Thank you
Best regards
John
John, you can use the Add Custom Action method my replies refer to. This let's you add a custom action to the SharePoint ribbon. You will need the free SharePoint Designer to make the necessary edits though. You don't need any programming to start the workflow since any workflows associated with the list/lib will be available in a pull-down list.
Nintex has documentation on this if I recall correctly.
Good luck
Thanks Gerard, I will attempt to implement this solution (although I may come back with questions!)