3

I have a List with two workflows. One that runs when an item is created/updated, and another that runs daily to perform a calculation. Emails go out when an item is created, updated, and expires.

There is a column Days Left that serves as a countdown depending on the number of days left until the Expiration date. Naturally this field updates everyday with the kickoff of the daily workflow.

My problem is that the Owner gets an email everyday because technically the item has changed since the Days Left is updated.

How do i say:

if one of the other fields is updated:

   send a notification and update the days left.

else:

   update days left

Right now I'm using

if Current:Item equals Modified...

4 Answers 4

4

This will be a challenge to do through Workflows. The reason being we can't get the previous value to compare and confirm which field was updated.

In such use cases we should use Event Receivers. It has AfterProperties and BeforeProperties. We can use those to compare and confirm whether the field updated is DaysLeft.

If you prefer workflow's then before sending email you can check the Modified field. If its modified by System Account (Assuming workflow is scheduled to run using System Account) then that means it was the previous workflow (Daily) which updated the item and you can skip sending emails.

1
  • Agreed, with this approach. Apr 10, 2015 at 1:15
1

Additionally to the answer of Amal Hashim, if is suitable for your situation, you can create the Days Left column as a calculated column based on Expiration and current date, avoiding the need for update Days Left from the daily executed workflow.

4
  • 3
    Calculated columns don't recalculate unless the item is modified, either by editing the item or server side code doing a System Update. Mar 24, 2015 at 20:12
  • Ok PirateEric, Could you give me the reference to the System Update operation by code? I'm not familiarized with that operation.
    – nilsandrey
    Mar 25, 2015 at 20:49
  • 1
  • Understood. Then if these approach is used must be combined with SPListItem.SystemUpdate. As the reference from Microsoft provided by PirateEric stated "Updates the database with changes made to the list item without changing the Modified or Modified By fields" while provoking calculated columns actually been recalculated.
    – nilsandrey
    Mar 26, 2015 at 15:48
1

The easiest way to determine whether an item was updated by workflow or actually updated by a user is to have your workflow run under a system account using the Impersonation feature.

Then, in your notification workflow, use the condition to check who the item was last modified by. If it's the system account, stop the workflow. Otherwise, send the notification as planned.

0

If you are using a SharePoint designer workflow, create a hidden fields in the content type. The purpose of this is to hold the value of the field you want to evaluate. In your workflow evaluate the value of the two fields, if they are different then you know a change occurred. The last step of the workflow is to update the hidden fields value so the next time a change is made you have the value to evaluate.

A bit of a hack and not as elegant as an Event Receiver but it does work.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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