cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Anonymous
Not applicable

SharePoint Flow - modify list item or create new if doesn't exist

Hey,

As you can see in the picture below, initally, I am using the trigger 'When file is created or modified (properties only)".  I need a condition to tell whether a file is being created up merely updated.  If it is new, then it will use the 'Yes' section and create a new item.  If a file is just being modified, then it will update the list item. But, I do not know how to set up the condition to do this?

 

Thanks!

 

create_or_modify.png

6 REPLIES 6
v-yamao-msft
Community Support
Community Support

Hi @Anonymous,

 

Yes, it can be achieved by using a Condition to check if the Created time and Modified time are equal.


If they are equal, then the file is new. While if they are not equal, then the file is being modified.


From the screenshot, it seems that you are trying to create/update item in a SharePoint List. When using the “Update item” action, you will be asked to specify the Id for the item.


To get the Id field, you could consider using the action “Get items”, then adding a Condition to filter the one that is required.


Please take the following screenshot for a reference.

3.PNG


If you need more help, please feel free reply.

 

Best regards,
Mabel Mao

Community Support Team _ Mabel Mao
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

I've found that this is not always accurate (although I'm not sure why).  I have records with only 1 version where the created and modified time stamps differ by several milliseconds. I've had to modify my flow to check if they're within a few seconds of one another, which doesn't feel like a great solution.  Would love something more iron clad. 

I ended up changing my flow so that I look at the version of the item.  If it is 1.0, then it's new...otherwise it's being modified.  Versioning must be enabled for this to work.

 

HTTP Request to get version and store it in a string variableHTTP Request to get version and store it in a string variableCompare the string variable value with '1.0'Compare the string variable value with '1.0'

@mjhufford

 

I am trying your suggestion. But, The condition in my Flow does not have  'Edit in Advanced Mode' .  I wonder if it is because the site is on SharePoint online 2013 but not SharePoint online 2016.  I am stuck in the last step.  

I really hope to see that your suggestion works for me.  Thanks.

 

Initialize_Variable.PNG

Testing with different tenant sharepoint site - I believe this is in SharePoint 2016 - 'Condition' has 'Edit in advanced mode'.  But, when I tried to save the flow.

Got error: The template validation failed: 'The action(s) 'SPRest-Verison' referenced by 'inputs' in action 'Initialize_variable' are not defined in the template.'.

 

SP2016_Initialize_Variable_save_error.PNG

mjhufford
Frequent Visitor

I'm not sure about that one.  Sorry.

Helpful resources

Announcements
MPA_User Group Leader_768x460.jpg

Manage your user group events

Check out the News & Announcements to learn more.

V3_PVA CAmpaign Carousel.png

Community Challenge - Giveaways!

Participate in the Power Virtual Agents Community Challenge

Carousel 2021 Release Wave 2 Plan 768x460.jpg

2021 Release Wave 2 Plan

Power Platform release plan for the 2021 release wave 2 describes all new features releasing from October 2021 through March 2022.

R2 (Green) 768 x 460px.png

Microsoft Dynamics 365 & Power Platform User Professionals

DynamicsCon is a FREE, 4 half-day virtual learning experience for 11,000+ Microsoft Business Application users and professionals.

Top Solution Authors
Users online (2,080)