4

I'm having 'fun' trying to prevent a workflow from running on a list item if the workflow has already run. The workflow runs each morning and emails item owners if their item hasn't been updated in over a month. I understand that the workflow updates its own little history with a success message. There's even a new column magically created in the list for each workflow.

To prevent an email being sent every time the workflow runs on items already captured by it (for example one of the workflows checks if an item was last updated within the last one to two months) I wanted to add a condition so that

if this item has a success / completed entry in the workflow history, stop processing the workflow

I'm really struggling to get anywhere with finding the status information within the workflow builder. Is anyone able to shed some light on this please?

Many thanks,
Matthew.

UPDATE: For now I have set up my own columns and hidden them away to record when a workflow has sent out an email. When the conditions are no longer being met the value of the column is reset accordingly and the process can start over. This works fine but surely there's an easier way of doing this out of the box. I should be able to dip into the workflow history or the item itself and easily assess what has happened as part of a workflow.

3

Your item has a field where the status of the workflow is stored (internal field name is dynamic, as there could be more than one workflow per item, but the field's internal name ends with "WF"). Field has a special value type "WorkflowStatus".

Possible states:

NotStarted = 0
FailedOnStart = 1
InProgress = 2
ErrorOccurred = 3
StoppedByUser = 4
Completed = 5
FailedOnStartRetrying = 6
ErrorOccurredRetrying = 7
ViewQueryOverflow = 8
Canceled = 15
Approved = 16
Rejected = 17

(See also: https://msdn.microsoft.com/en-us/library/microsoft.sharepoint.workflow.spworkflowstatus.aspx)

So you could check the field value to make sure if it has already run for the item.

But the question is if you need to re-check the item after one month in any case - if yes, then simply checking the state won't be enough.

  • Thank you Shihan. I will try this one. I had noticed the column but was testing against the status as a word not a code. I'm thinking really I need to have an item in the workflow store my own "yes, this check has been done" value. I'll let you know how I get on. – Matthew E Cornish Feb 14 '17 at 8:39
  • I've tried this Shihan but was unable to identify the column (which I thought previously I had managed to identify) so I have tried an alternative solution of my own for now. – Matthew E Cornish Feb 14 '17 at 15:37
  • This is good, except that after 60 days (by default), that field gets cleared out. You can change the default to whatever you need. However, that ends up storing a lot of data if you keep it forever. I would personally use the method you're using now. – Erin L Feb 14 '17 at 15:42
  • Thank you for that Erin. For now I believe I will be sticking with it :) – Matthew E Cornish Feb 15 '17 at 9:31
1

I set up my own columns and hid them away to record when a workflow has sent out an email. When the conditions are no longer being met the value of the column is reset / blanked and the process can start over.

This works fine but surely there's an easier way of doing this out of the box. I should be able to dip into the workflow history or the item itself and easily assess what has happened as part of a workflow.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.