I would say it's a bug.
I can reproduce the same behaviour. I even noticed cancel is invoked for correctly completed workflows.
Do you know, if this is already on a buglist and if it's in sight when this is gonna be fixed, Frank Field?
Hi Ricky Mattischeck, Marian Hatala, this will be expected behavior when using this method. If the 'terminatePreviousInstances' option is set to true, it will terminate any previous workflow instances associated with this item regardless of the state. If you do not desire to have all of the workflows under that workflow name for this list item to be cancelled, you will need to set that option to false.
thanks for explanation Dan Burke
however, to be honest, I miss the point not to check/consider workflow status. who might want to cancel already completed or cancelled workflows? it's even not possible to do it manually since it doesn't make any sense.
furthermore, even if I set terminatePreviousInstances to false it still goes through all the instances of current workflow version, REGARDLESS of status. so, if I have 1000 completed workflow instances of current version and 1 running instance which I'm willing to cancel, I still get 1000+1 notifications about cancelled workflows.
I know, you may say to switch off notifications in site settings. but that's not an option, I want to be notified about failed RUNNING workflows.
I'm sorry, I somehow can not accept this as designed feature.
and final note, this topic is about notifications. but i would be interested in what's exactly going on in background when already completed workflow is to be cancelled. likely other unforeseen effects might arise (eg. it might affect cleaning jobs)
I can confirm , that this effect also occurs if the setting for previous versions is false.
And the setting MUST be true because it could be that a new version of the workflow is published while the instance of the older version is still running but the workflow itself should be cancelled for the listitem, no matter which version the workflow is.
I can't image this is an expected behaviour as, like Marian said, there is no sense in getting noticed for already (maybe long time before) completed/errored workflows.
To be honest, I have used this for terminating errored workflows which appear to be dropped into the same bucket as cancelled.
do you mean 'the same bucket' like already cancelled workflow were being cancelled once again?