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

CL7 1 Reputation point
2021-07-30T14:19:09.92+00:00

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 Development
SharePoint Development
SharePoint: A group of Microsoft Products and technologies used for sharing and managing content, knowledge, and applications.Development: The process of researching, productizing, and refining new or existing technologies.
3,031 questions
SharePoint Workflow
SharePoint Workflow
SharePoint: A group of Microsoft Products and technologies used for sharing and managing content, knowledge, and applications.Workflow: An orchestrated and repeatable pattern of business activity, enabling data transformation, service provision, and information retrieval.
599 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Echo Du_MSFT 17,176 Reputation points
    2021-08-02T05:46:47.64+00:00

    Hello @CL7 ,

    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.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.