SharePoint 2013 Workflow: Check if list item exists

For a customer we are building a complex approval process on Office 365 with SharePoint 2013 workflows. During the process we need to check if an list item (in an other list) existed. There is no default action that lets you do this. You can however us the set variable and if statement action to figure out if the item you are looking for exists or not. This is a useful trick to know when working with SharePoint 2013 workflows.

Solution

  1. Create a SharePoint 2013 workflow.
  2. Create a  variable called ContractItemID, here we will try to store the ID of the list item we are trying to find.
  3. Set the variable to 0 (zero).
  4. Then we need to try and set the ContractItemID variable with the ContractID of the item we are searching. This can be from the same list or a different list.
  5. I am trying to find the ID of a list item with a specific Contract Number.
  6. If the workflow finds an ID the ID will be stored in the variable, if no item is found then the ContractItemID value will remain 0 (zero)
  7. Use an if statement to determine if the list item exists.

 

Share

18 Replies to “SharePoint 2013 Workflow: Check if list item exists”

  1. Thank you very much for your post! I am working on SPD workflow, and it is suppose to create and if it exists update an item in another list. I was able to achieve both but when it updates, it duplicates. The workflow starts when an item is created and item is changed. How can I prevent it from duplicating. Please help

  2. Hi Ben,

    Thanks for your response.
    I have two lists List1 with columns(Title,Author…) and List2 with columns(Title, Author). When I create a new item in List1, it copys the item using workflow from List1 to List2 (using Create item in this list (Output to Variable: create)), which is working fine but when I update an item in List1, it updates the matching item in List2 and creates another entry in List2 using(Update item in this list). I am trying to copy items from List1 to List2 and if I make any change to one of the columns(Title, Author) in List1 items then it should modify items in List2 columns(Title, Author).

    Thank you for your help.

  3. A possible solution is to create two workflows. One that start on when a new item is created and that created the item in list number 2. Then a second workflow that starts on update, that workflow then updates the related item in list 2.

  4. I was thinking to do ‘call HTTP service’ and count the no: of item through rest. But, this one is a lot easy. Thanks. 🙂

  5. I’m not sure if you still monitor this – but my list has over 5000 items and it seems that when I check if the item exists, it throws an error when it doesn’t exist : The attempted operation is prohibited because it exceeds the list view threshold enforced by the administrator. It works fine if the item does exist.
    So I’ve been trying for a while now to prevent this error but not successful. including this one.
    Any thoughts would be appreciated.

  6. Stupendous! This is wonderful! Very elegant fix that addresses a simple task. Love it.

  7. Hi Ben.

    I’ve only just found this article but wondered if you could assist. You state “This can be from the same list or a different list.” but if I do this in the same list, the workflow will identify the current item. How can I look for an an existing list item and exclude the current item?

    Thanks!

  8. Thank you so much for this explanation – it worked for me!!

    In case this helps anyone else, my lookup didn’t reference the ID field. The library I need to update will have one file per employee reference (which is a unique identifier consisting of first initial + last name + number if necessary for common last names). I called my variable EmployeeReference, which is also the name of the library it’s updating. So the step in my workflow looks like this:

    Set Variable: EmployeeReference to EmployeeReference:Title

    If Variable: EmployeeReference is not empty
    Update item in EmployeeReference
    If Variable: EmployeeReference is empty
    Create item in EmployeeReference

    Works great!

Leave a Reply to Jefin Mathew Cancel reply

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