How to copy and UPDATE list items from one SharePoint list to another list (Part 2)

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
[Music] in the last week video that I will put a link right there we saw how we can make a copy of the SharePoint list items from one list to another list as soon as the item is created in one list even if the list is in a different site collection or even a different host it doesn't really matter but today I want to take it to the next level that list and copy item was very simple today I want to show you how you can track updates from one list to another so basically if the item is created it creates the same item they are on the other list but if the item is updated if you want to copy the updates and update the list item in the destination let's see how it is done if you haven't watched the last week video I have a quick review on it so we have two lists here list one and list two and we want to copy any item that is created and list one to list two and these two lists are in two separate SharePoint site collections and because your modern sites they are not sharing the same content type now any item that is created in list 1 should be copied in list 2 last week we just made the copy but today if you want to make the update so if the list item is created here we should copy it here if the list item is updated here the same list item should be updated in list 2 now to make this happen we use the shared content type using the SharePoint content IPOP so we created the content type here and we published it to the entire tenancy so we could actually have the exact same content type to list1 and list2 although they are into separate site collections so basically we have everything ready let's rock and roll so these are the sites from last week if you have site one and inside site one we list one on the other side we have side to and underside - we have list - we created a flow called list item copy demo and inside that if I click on edit and item is created on list 1 and create item it creates the same list item in list 2 now we want to take it to the next level to do that first of all I get back to the list of my flows if you created this list last week with me you'd better just turn it off so it doesn't fire any more because we don't want it to interfere with the new flow I create a new flow just like before I click on instant flow and skip I'm searching for SharePoint and under SharePoint this time I want to say when an item is created or modified so this time I want to watch both created and modified that's a main difference then I also want to give this list a name I give it a name track updates a new list I cannot save it yet because there is no action but before I start this action I want to show you the strategy that I'm gonna follow to be able to track items that I've created in list 1 I should have an identifier that is trackable in each site - list - this one is not as easy as you think we all know every SharePoint list item has an ID I can see it here if I just edit this view I can click on ID and this ID is gonna show me here let me just bring it to the first column okay so i have ID here and let me just add a test record here so we will see the value of it test city is something something something something and assigned to ice okay and I click on safe so as you can see the ID is 6 I have no control over it and when the item is created there in the other side again we don't have any control over it so technically we cannot copy this ID from here and take it to the other list so what is the solution solution is very simple instead of taking this idea and trying to copy it in the destination list we need to create another column that stores the ID from site 1 to do that I just go to the list directly not to the content type to the list directly and I add a column of type single line of text and I call it source ID it's a single line value and I just click it and save it so source ID is the column that I just created and it's supposed to get an ID from the source list and actually when I'm copying the list as soon as it is created I can get this ID and copy there but if you consider importing multiple lists like lists one to one single list and merger result this ID can have duplicate in the site too so for that we need to use an internal identifier for every record that you do not even see it in the view but luckily flow can capture it so let's capture that one and work with it next time if we want to modify it we look it up by the source ID and then we update it let's see how I go to my flow and inside this when the item is created or modified I pick up site 1 and I get list 1 and again I have to pick the Advanced Options this time because remember that identifier is a hidden field so I say use all the columns and right after that I add a new step and I put just compose to evaluate the identifier so I come here dynamic content and under this when an item is created or modified I pick the field identifier let's see how it looks like so I just saved it I go back to list one I add another item and let the floor I test Mississauga company home and email test at something.com hobbies no assigned to you can assign it to myself and I click on save and we just pray for the flow to run let me go - let me go to my flows again and click on it yes it ran five seconds ago and if I click on it you will see the identifier here that it looks like lists list one and an identifier and that identifier partly includes the actual ID which is fine so when the item is created if I copy this identifier in the destination I can look up the same item in the destination by this ID complicated I don't think so let's do it so let me take you to edit when the item is created this or modified we need to know first of all is the item already there or not but before we go there let's make it simple let me just delete this we don't need it anymore and let me just copy it so SharePoint I picture point and I pick create item create item is going to create an item inside - list - and now title goes for title city goes for city company goes for company email email hobbies hobbies from source a site to claim everyone except external users we don't want to do that if you want to enter the custom value from the source actually add this assign to just assigned to built inside column I just added it to the content type on the hub so that it's not going to be just plain text field so assigned to claim I can pick up the assign to claim here again from the source now source ID is going to be the identifier of the source so let me pick it up from here identifier so it's gonna come here content type ID I again pick up custom value and I can pick the content type ID from source because it's coming from the hop content types in both side collection share the same ID so let me save it now and see if you can copy it this is just like what we did last week so I click on new all list one and I give it another one new title and city is gonna be my city company is going to be my company email something that a.com hobbies gaming assigned to myself and again I save it when I save it if I go to my flow let me go to my flows and see if it actually executed let's refresh it see if we get lucky it may take 2 to 3 minutes so let me pause the timer okay we got it let's get inside it and see what we did create item apparently worked let's go to situ and make sure if it is created great my company bla bla bla and we have the source Idina great so if I go back to the flow this trigger fires even if the item exists or even if I make an update so when this trigger is fired I need to check if the item exists in the destination so let's see how we can do it 20 item is created or modified we have the identifier the only thing that we need to do first we need to look up the item in the destination folder the way that we do it we use SharePoint I click on SharePoint and we go to get items make sure you are using get items not get item because get items allows you to search for the fields other than ID but if you use get item you have to provide one specific ID that is pointless for us so I use get items I search the destination which is site 2 and list 2 the only thing that we need we need to query that list for a specific value you cannot use for each group because if that list gets big you will have troubles the only way ahead of you is using all data filter or data filter is very simple to use if you are familiar with OData great if you are not familiar with OData I will put a link here for you right on the top of the page there is another video go watch it and come back and continue with it for the filter I would say source ID equals single coat and inside that single coat I go to my source which is when an item is created and I pick the identifier and add it here so basically now if getitem find the value it means that the item is updated here otherwise it is created let me save it and check the condition right after that so I click on this one I say that an action condition I pick a condition which is my if statement and for the value the value that I want to check here or the number of items in the get items after I run that OData query so here I need to get the number of the items I come here I need to write a tiny expression for this I click on expression and I use the function Len Len is a function that accepts an array of items and returns a number of items here so basically if I go back to the dynamic content and I get the list of items if this expression returns 1 it means that item exists if it returns 0 it means the item does not exist fantastic so if I just click on OK and I say if this land is equal to 0 if it's equal to 0 it means that we need to create item otherwise we need to get this single item and update it so basically I would say SharePoint I pick the SharePoint and I say update item I select the destination list which is going to be cite to the list name is going to be list to the idea that I have is the idea of the item that I looked up here because it's an array if I just add it here it will add a for each loop automatically I'm getting it from get items see the ID I get it so it automatically puts it in then in an apply to each which is fine because it runs only once and the rest is just like before now the title is gonna be titled not from get items but from the original trigger so be a little bit careful about it let me search for title not from get items from when an item is created or modified so scroll down this is the title city again I am searching for city not from the get items from the trigger company is the same thing I go to company not the company from the get items but from the trigger email same thing email again not from get items from trigger hobbies I search for hobbies from the trigger assigned to claims again from the trigger assigned to claims not from get items from the trigger you gets it source ID I really don't need to update it but if I leave it blank if it it will overwrite it to the blank value so I go down here and I pick up source ID it doesn't really matter from where you get it because only the destination has a source ID field at the content type ID I pick it up again as the custom value and I get the content type ID from trigger again theater so when the trigger is fired will look for the item based on that source ID using the OData query then we check the condition if the land of the item equals 0 means that item does not exist we need to create it otherwise we need to look it up and update it let's test it save I go to list 1 and I add a new item and I call it fresh whiten City Toronto company my company email leaders are at somewhere calm yeah okay doesn't matter hobbies hunting assigned to I assign it to myself and I click on save so the new item is created let's go back to the destination and see when we get it here just refresh it or maybe let's go to the flow and see when it updates so let me click on here 10 minutes ago let's refresh again let me pause the video great it felt let's see where it felt so if we go inside it get items condition felt unable to process temperate language condition at line 1 the tablet language function line expects that parameter can be an array or string its parameter to be an array always string the provided value is an object ok let's see what we got from here ok we got to get the body value for the grade item so let me get back here so under the condition I just remove this we go for the I go to expression again I go to plan open let's go to the dynamic content on the gate item let's get the value this time and this time it's gonna be okay let's save it again go back to the first item again I create a new item title ABC after error fix city is gonna be truant again company my company email blah blah blah hobbies hunting assigned to myself alright so let's go back there again to the flow and see when it runs this time it says succeeded so if I go back here condition goes to the create side and we actually created this so let's go to site 2 let's refresh it and ABC after error fix perfectly copied so now let's go back to site 1 again and let's update this so let me click on this one edit all and I change the transfer of the company to you so instead of my company it's going to be your company and instead of Toronto it's gonna be ok I save it again and I wait for the flow to see what it does again let's go back to my flows let's wait for that to complete and this is the update so let's get inside it and see what it did condition and as you can see the condition is false and it went to the other side running this apply to each data is only one item and it updated the item let's go back to SharePoint and inside SharePoint you see the city's oral now and the company is your company and that was all about it thank you for watching I hope you enjoy the video if you are not a subscriber please push that subscribe button and more than anything please click on the like because these are the days that I need those likes more than anything else thank you for watching [Music]
Info
Channel: Alireza Aliabadi
Views: 21,505
Rating: undefined out of 5
Keywords:
Id: yLBohC1Rw00
Channel Id: undefined
Length: 22min 33sec (1353 seconds)
Published: Sun May 17 2020
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.