Home › Forums › General discussion › Workflow Termination
- This topic has 9 replies, 2 voices, and was last updated 5 years, 7 months ago by Alexander Bautz.
-
AuthorPosts
-
-
April 17, 2019 at 11:51 #24873
Hi Alex,
I was checking maybe if we can terminate a workflow using dffs, what do you think can we do that? i am starting a workflow when a status field is changed i have the same scenario but to terminate a workflow. if you don’t have time to check it maybe if you can share with me what’s the best way to do it and i will develop the function and add it in my custom js.
Thank you.
- This topic was modified 5 years, 7 months ago by HYM.
-
April 17, 2019 at 21:06 #24883
I haven’t done this before, but a Google search led me here: https://sharepoint.stackexchange.com/questions/174755/how-to-stop-a-sharepoint-workflow-using-jsom
You can try using this in Custom JS to terminate your WF.
Alexander
-
April 19, 2019 at 10:19 #24913
okay thanks Alex, i tried this solution and it’s not working 100% but after doing some research and checking your solution to start a workflow using a button i fixed the code and it’s working fine with me now, if you want i can share the code here.
-
April 20, 2019 at 11:44 #24928
Yes, please share your code – I know others are looking for a similar solution.
Alexander
-
-
April 20, 2019 at 10:58 #24923
Alex if i want to call a function from a rule and set some parameters for it i can’t do that?
i’ve added a screenshot check it.
Attachments:
-
April 20, 2019 at 11:42 #24926
You cannot add an argument to the function here, but you can create a function in custom js and call this function from your rule:
function callMeFromRule(){ yourOriginalFunction("your_argument"); }
Alexander
-
April 20, 2019 at 12:02 #24934
Alex i’m facing weird behavior from calendar field, when i click on the calendar icon it jump to the top of the page any idea?
-
April 23, 2019 at 09:45 #24952
I’m not sure why this happens, but I have had the same issue in another list and made some changes to a built in function to fix it. You can try adding this to your Custom JS:
function OnIframeLoadFinish() { var a, top; top = jQuery("#s4-workspace").scrollTop(); if (typeof this.Picker != "undefined") a = this.Picker; if (a !== null && typeof a.readyState !== "undefined" && a.readyState !== null && a.readyState === "complete") { a.style.display = "block"; if (typeof document.frames != "undefined" && Boolean(document.frames)) { var b = document.frames[a.id]; if(b !== null && typeof b.focus === "function"){ b.focus(); } } else { a.focus(); } } setTimeout(function () { jQuery("#s4-workspace").scrollTop(top); }, 0); }
Alexander
-
April 20, 2019 at 11:58 #24930
spjs.workflow = { "text":{ "successMessage":"The workflow was terminated", "errorMessage":"Something went wrong. To try again, reload the page." }, "data":{ "dlg":null }, "initListItemWF":function(subscriptionId){ if(typeof SP.WorkflowServices === "undefined"){ jQuery.getScript(_spPageContextInfo.webServerRelativeUrl+"/_layouts/15/sp.workflowservices.js",function(){ spjs.workflow.terminate(subscriptionId); }); }else{ spjs.workflow.terminate(subscriptionId); } }, "terminate":function(subscriptionId){ var listId = ""; var itemId = GetUrlKeyValue("ID"); console.log(subscriptionId); //spjs.workflow.showProgress(); var ctx = SP.ClientContext.get_current(); var wfManager = SP.WorkflowServices.WorkflowServicesManager.newObject(ctx, ctx.get_web()); var workflowInstanceService = wfManager.getWorkflowInstanceService(); var wfInstances = workflowInstanceService.enumerateInstancesForListItem(listId, itemId); ctx.load(wfInstances); ctx.executeQueryAsync( function(sender, args){ var instancesEnum = wfInstances.getEnumerator(); while(instancesEnum.moveNext()){ var instance = instancesEnum.get_current(); console.log(instance.get_workflowSubscriptionId().toString().toUpperCase()); if(instance.get_workflowSubscriptionId().toString() == subscriptionId){ console.log("Matched"); workflowInstanceService.terminateWorkflow(instance); ctx.executeQueryAsync( function(sender, args) { spjs.workflow.closeDlg(); SP.UI.Notify.addNotification(spjs.workflow.text.successMessage,false); }, function (sender, args) { spjs.workflow.closeDlg(); console.log(spjs.workflow.text.errorMessage); //alert(spjs.workflow.text.errorMessage); } ); } } console.log("terminated"); }, function(sender, args) { spjs.workflow.closeDlg(); console.log(errorMessage); //alert(errorMessage); } ); }, "closeDlg":function(){ if(spjs.workflow.data.dlg != null){ spjs.workflow.data.dlg.close(); } }, "showProgress":function(){ if(spjs.workflow.data.dlg == null){ spjs.workflow.data.dlg = SP.UI.ModalDialog.showWaitScreenWithNoClose("Please wait...", "Waiting for workflow...", null, null); } } };
-
April 20, 2019 at 11:59 #24932
.ms-notif-box{
display: none !important;
}`to hide the message “Workflow terminated”
-
-
AuthorPosts
- You must be logged in to reply to this topic.