In SPD2013 i have created a new workflow which updates the value of an item in a list. The workflow works fine, however, the workflow opens a new window each time a user initiates the flow. Is there a way to prevent this? Please note that the workflow is initiate via a custom list item menu action.
2 Answers
The workflow with SharePoint 2010 workflow Platform type must have an initiation form. When user manually start the workflow, the initiation form will open. We cannot delete the initiation form for the workflow with SharePoint 2010 workflow Platform type.
If you want to create a workflow without the initiation form, create workflow with SharePoint 2013 workflow Platform type in SharePoint Designer. By default, the 2013 workflow does not have the initiation form. If someone creates an initiation form for a 2013 workflow, you still can delete it.
You can start a SP2010 workflow with a single click but it involves some custom code. I have written a blog post about it here: http://spoodoo.com/starting-workflows-1-click/#more-1123
First you need two libraries, jQuery and SPServices
Here is the code that you have to embedd on the page from where you want to start the workflow:
function startWorkflow(argObj) {
var props = argObj;
if (typeof props.itemId == "undefined") {
alert('Property \'itemId\' missing!');
return;
}
if (typeof properties.workflowName == "undefined") {
alert('Property \'workflowName\' missing!');
return;
}
var url = window.location.protocol + '//' +
window.location.host +
$('table div[id="' + props.itemId + '"]:not(:visible)').attr('url');
var wfGUID;
$().SPServices({
operation: "GetTemplatesForItem",
item: url,
completefunc: function(xData, Status) {
$(xData.responseXML).find("WorkflowTemplate").each(function(i, e) {
if ($(this).attr("Name") == props.workflowName) {
wfGUID='{'$(this).find('WorkflowTemplateIdSet').attr('TemplateId')+'}';
};
});
if (typeof loadingImage != 'undefined') {
var style = "#wfoverlay{" +
"position: absolute;" +
"left: 0;" +
"top: 0;" +
"bottom: 0;" +
"right: 0;" +
"background: #000;" +
"opacity: 0.38;" +
"filter: alpha(opacity=80);" +
"}" +
"#wfloading{" +
"width: 16px;" +
"height: 16px;" +
"position: absolute;" +
"top: 50%;" +
"left: 50%;" +
"margin: -8px 0 0 -8px;" +
"}"
var div = $("<div />", {
html: '­<style>' + style + '</style>'
}).appendTo("body");
var over = '<div id="wfoverlay">' +
'<img id="wfloading" src="' + props.loadingImage + '">' +
'</div>';
$(over).appendTo('body');
};
$().SPServices({
operation: "StartWorkflow",
async: false,
item: url,
templateId: wfGUID,
workflowParameters: "<root />",
completefunc: function(xData, Status) {
$('#startWorkflowOverlay').remove();
if (Status == "error") {
if (typeof props.failMessage != 'undefined') {
alert(props.failMessage);
} else {
alert(Status);
}
} else {
if (typeof props.successMessage != 'undefined') {
alert(props.successMessage);
}
window.location = window.location;
}
}
});
}
});
};
Now in your custom action, instead of selecting ‘Start a workflow’ you put the following code into the Navigate to URL
field:
javascript:
startWorkflow({itemId:{ItemId},
workflowName:'put_workflow-name_here',
successMessage:'Success',
failMessage:'Error',
loadingImage: 'url_of_loading_animation',})
And that should do it.