Delete old Item with new Item using SharePoint Designer Workflow

I have a scenario from SharePoint MSDN Forum, which states,

If I have an item Title named ‘Kumar’ and I am going to create a new item with Title named ‘Kumar. I need to delete the old item.

Note: In following example I have renamed the Title Display Name to ‘Names’

Here I am using SharePoint Designer workflow to achieve this by following way,

  • I have to get the old List Item,
  • Then compare the current (new item) with the old item
  • And the Old Does not have the Current Item Id
  • If above two steps are true, then delete the old item.

I have elaborated the above steps with the following activities,

  1. Create a List Workflow and associate to a List and Set the Start Option as “Start Workflow automatically when an item is created”

  2. In workflow step, First we have to create a workflow variable to get the item id which matches value entered in Current Item.

  3. Using “Set Workflow Variable” activity we are getting that Item id. Add the parameters as shown below. And name the workflow variable as ‘OldItemId’



  4. In the above figure I am getting the Item ID from the last item which matches the same vale for the Names field.

  5. For the following 2 steps, we have to If Current Item field equals value condition activity.

  6. Now we have to compare the Current Item value against the item returned by ‘OldItemId’



  7. Then we have to compare the ‘OldItemId’ not same as Current Item Id.



  8. The Use the Delete Item activity to delete the item based on ‘OlditemId’



Now the duplicate was item added with a same value will delete the old item.

3 thoughts on “Delete old Item with new Item using SharePoint Designer Workflow

  1. Andrew

    If I don’t have an item called Kumar and create a new one The workflow seems to delete the item straight away, i.e. not leaving at least 1 (the newest/latest) in the list.

    Wat might I be doing wrong?

    Reply
  2. Andrew

    Managed to figure the above out. I reversed the If Current Item field equals value condition activity. Now they want to keep historic list entries. – That’s the next challenge.

    Reply

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>