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
- Create a SharePoint 2013 workflow.
- Create a variable called ContractItemID, here we will try to store the ID of the list item we are trying to find.
- Set the variable to 0 (zero).
- 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.
- I am trying to find the ID of a list item with a specific Contract Number.
- 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)
- Use an if statement to determine if the list item exists.
Perfect, thanks for sharing!
My pleasure 🙂
Thank you very much! It solved a huge problem I had =)
You are welcome!
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
Hi Nabir,
What do you exactly mean by “it duplicates”? I am not sure what you mean by this.
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.
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.
Thank you so much for all your help! It works perfectly.
Hi Nabir,
Can you tell me how it worked for you. I am still getting duplicates for the update.
I was thinking to do ‘call HTTP service’ and count the no: of item through rest. But, this one is a lot easy. Thanks. 🙂
You are welcome!
brilliant idea! saved me hours on this! thank you so much!
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.
I have the same problem. Did you ever find a resolution? I’ve tried many different things but it still does not work if the target lookup item does not exist.
Stupendous! This is wonderful! Very elegant fix that addresses a simple task. Love it.
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!
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!