2

I wonder if you can help me here.

I have a field on a Sharepoint list called 'Developer'. When the name in this field changes I want to store this into a field called 'Previous Developer'.

Ideally, I'd like this to be set using a workflow.

I've tried a variety of things on a workflow for instance storing the Developer field as a variable. However, it always sets the Previous Developer at the same time as the Developer value. I want the Previous Developer to be a historic value to only be populated when the Developer value changes.

eg:

if current item:Developer not equals current item:Previous Developer
set Previous Developer to Developer

The workflow is set to run on created & changed.

What's the best way to achieve this?

I've been staring at this for far too long, so I think I'm missing something obvious!

2 Answers 2

3

In SharePoint Designer 2013 Workflow, Although you can wait until a specific field changed. but Unfortunately, you can't catch the Field old value, because of the Workflow is executed after the item is updated.


The Practical workaround solution is:

Create an Event Receiver on Item Updated or 'Item Updating' to get the old and new value.

  • To get old value on Item Updated

         string before = properties.BeforeProperties[properties.ListItem.Fields["yourfield"].InternalName].ToString();    
    
  • To get new value on Item Updated

         string after = properties.AfterProperties[properties.ListItem.Fields["yourfield"].InternalName].ToString();
    

Note: in case you are using Item Updating you can get the old value and new value as the following:

  • The old value use properties.ListItem
  • The new value use properties.AfterProperties
1

Your current system allows you to detect the change.

  • If the two fields are equal, then this particular field wasn't changed,
  • if they are different then it was changed. Then,
  • if they're different, update the previous field to the current value so that it can detect the next change. Good. Add another field called "historical value" (or rename your current field, as my naming suggestion here is not great).

When a change is detected, before setting your previous field, set the historical field to the current value of previous.

So, given a new record with a developer of Amy, before the workflow runs, the values will be:

dev: amy
prev: (blank)
hist: (blank)

after the workflow:

dev: amy
prev: amy
hist: (blank)

Then, after changing it to mark, before the workflow:

dev: mark
prev: amy
hist: (blank)

Since dev != prev, the condition is met, and prev will be copied into hist, and then the current value will be copied into prev. So after the workflow runs, you'll have:

dev: mark
prev: mark
hist: amy

Of course, M.Qassas has a nice solution as well that doesn't require additional fields. This answer requires the extra field, but doesn't require code.

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.