-
-
Notifications
You must be signed in to change notification settings - Fork 58
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
stopWorkflow does not work inside NodeJS : ReferenceError: document is not defined #162
Comments
There is no API to stop a workflow. So as a workaround the script opens an iframe to the Workflow Instance page where there is the "stop workflow" option. And then the form is posted to cancel the workflow. In a Node environment, I'm not sure right now. I'll have to do some research to see how it's possible to have the same kind of behavior. |
I see, yeah this function is actually my main purpose behind using your package. So any help at all is greatly appreciated! |
I'll need a few days to find the time to work on it. |
I don't have the bandwidth right now to investigate. If you cannot wait for a couple of weeks, then I'll invite you to explore by yourself the below solutions:
You have to use async function run() {
let params = await $SP().getWorkflowID({ID:itemID, workflowName:"The workflow name"});
if (params.instances.length===0) return "No instance available for this workflow/item ID.";
let pageUrl = params.instances[params.instances.length-1].StatusPageUrl;
// then call "pageUrl" with either `jsdom` or a puppeter script
// once the page is loaded, you need to trigger the below from the page:
// window.__doPostBack('ctl00$PlaceHolderMain$HtmlAnchorEnd','')
} |
I took some time to find out a solution. It took me one hour, and here is how to proceed: https://github.com/Aymkdn/SharepointPlus/wiki/Stop-a-workflow-2010-from-Node-Server-Application |
seriously, thank you very much for resolving this so quickly! |
I'm noticing this stopWorkflow solution works perfectly for workflows that were automatically started. For workflows that were manually started, the stopWorkflow function will not successfully stop the workflow. Can you please confirm that this is working for you with workflows that have not been automatically started on item creation? |
I don't know. I'll have to create a list and a workflow and test. |
I've just tried, and it worked as expected: I manually started a workflow (that is doing a "pause for 5 hours") then I used the code to stop it, and it worked. |
Interesting. Can you please try starting two workflows and using a for loop to iterate through them and stop both of them? |
Sorry, I don't have the time to do it. Please, refer to my previous comment. |
Yeah I've tested this thoroughly and it seems like the stopWorkflow function is only working for the very first workflow. It has no effect on other workflows. |
It seems there is an issue in my code as the |
I've just published v6.1.4 that fixes |
Thanks again sir! |
This is the error I receive when attempting to use stopWorkflow in an external NodeJS API:
my execution:
sp.list("ListName","http://company.com/").stopWorkflow({ID:6736, workflowName:"2010 Workflow"});
the error:
The text was updated successfully, but these errors were encountered: