Workflow Termination

Forums General discussion Workflow Termination

Viewing 5 reply threads
  • Author
    Posts
    • #24873
      HYM
      Participant

      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 2 years ago by HYM.
    • #24883
      Alexander Bautz
      Keymaster

      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

    • #24913
      HYM
      Participant

      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.

      • #24928
        Alexander Bautz
        Keymaster

        Yes, please share your code – I know others are looking for a similar solution.

        Alexander

    • #24923
      HYM
      Participant

      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:
      • #24926
        Alexander Bautz
        Keymaster

        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

      • #24934
        HYM
        Participant

        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?

      • #24952
        Alexander Bautz
        Keymaster

        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

    • #24930
      HYM
      Participant
      
      
      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);
      		}
      	}
      };
    • #24932
      HYM
      Participant

      .ms-notif-box{
      display: none !important;
      }`

      to hide the message “Workflow terminated”

Viewing 5 reply threads
  • You must be logged in to reply to this topic.