question

CL7-5710 avatar image
0 Votes"
CL7-5710 asked EchoDu-MSFT commented

Workflow : how to copy from one list to another with datestamp (baselining)

Hi,
I have many fields on a SharePoint list and would like to have all of them copied to a new list whenever a copy is required. The difference is that I would like all items copied as they are with a new field updated with the datestamp.

Therefore each time copies are taken, they add to the second list with a new date. They do not overwrite the existing items on the second list, mere copy all list 1 items again with a new date stamp. This would also mean it keeps the 'modified' and 'modified by' on the new list, but this is really a secondary requirement and presumably could be done with new static field names?

Any help much appreciated.


Thanks,


CL.

sharepoint-devsharepoint-workflow
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

EchoDu-MSFT avatar image
0 Votes"
EchoDu-MSFT answered EchoDu-MSFT commented

Hello @CL7-5710 ,

Welcome to Q&A Forum!

According to my research, we cannot keep the values of 'Modified','Modified by', 'Created', 'Created by' and other columns. Because they are defined by SharePoint, SharePoint will automatically obtain and store who created/edited item and when item was created/edited.

You can implement this design through the PowerShell command:

1.Source List: TestList

119658-testlist.png

2.Target List: CopyList

  • Create two "Date and Time" columns named "TestListModified" and "Datestamp"

119744-testlistmodified.png

  • Set "Datestamp" value is equal NOW()

119659-datestamp.png

  • Create one "Person or Group" column named "TestListModifiedBy"

119727-testlistmodifiedby.png

3.Please run the following powershell script as an admin:

 #Configuration variables
 $WebURL = "http://sp/sites/echo"
 $SourceListName = "TestList"
 $TargetListName= "CopyList"
     
 #Get Objects
 $web = Get-SPWeb $WebURL
 $SourceList = $web.Lists[$SourceListName]
 $TargetList = $web.Lists[$TargetListName]
     
 #Get all source items
 $SourceColumns = $sourceList.Fields
 $SourceItems = $SourceList.GetItems();
     
 #Iterate through each item and add to target list
 Foreach($SourceItem in $SourceItems)
 {
  write-host -foregroundcolor yellow Copying Item: $SourceItem["Title"]
     $TargetItem = $TargetList.AddItem()
     $TargetItem["Title"] = $SourceItem["Title"]
  $TargetItem["TestListModified"] = $SourceItem["Modified"]
  $TargetItem["TestListModifiedBy"] = $SourceItem["Editor"]
     $TargetItem.update()
 }

119690-powershell.png

4.Go back the CopyList , you can see the below screeshoot:

119649-copylist.png

Thanks,
Echo Du
===================================
If an Answer is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.





testlist.png (16.6 KiB)
datestamp.png (30.2 KiB)
powershell.png (24.3 KiB)
copylist.png (31.5 KiB)
· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Hello @CL7-5710 ,

Is there anything else I can help with regarding this issue?
You can comment us at any time and we will continue to follow up.

Thanks,
Echo Du

0 Votes 0 ·