none
How to update the system generated fields such as Created, Created by, modified , modified by and Comments for list items

    Question

  • I am working on 5 team sub sites, each sub site have 2 issue tracking lists which are based on 2 different custom content types.

    Now our customer asked us to merge these two issue tracking lists into one list, that contain all the items from the two lists. So for example if currently we have 10 items inside the first list and 5 items inside the second list, then the new list will have 15 items.

    Now currently I have around 60 items that need to be transferred inside the new list, and I do not want to over-engineer the case . So I am planning to do the following steps:-

    1. I will create a new list which represents the new list, without any items.
    2. Then I will manually copy/paste the content from the current 2 lists into the new list.
    3. I will hide the 2 old lists , so users will be adding /modifying the new list only

    Now this should work and it might take around 2 hours to complete which sound valid. But I am trying to find a way how I can preserve the following values inside the new list items:-

    1. Original created date.
    2. Original modified date.
    3. Original created by.
    4. Original modified by.
    5. Also the issue tracking list items  have comments inside it, and each comments have created date and created by which i need to preserve the original values of them.


    • Edited by johnjohn11 Wednesday, November 25, 2015 1:07 PM
    Wednesday, November 25, 2015 1:04 PM

Answers

  • Ok, so this little snippet of PowerShell should show you how to extract the version information from a list item, then in reverse build up a new item in the same list with the same version history.

    Hope this helps

    Paul.

    $web = get-spweb http://escdemos
    $list = $web.lists["VersionTest"]
    $sourceItem = $list.items.GetItemById(1)
    
    $versions = $sourceItem.versions
    
    $newItem = $list.items.Add();
    
    $versionCount = $versions.Count;
    
    ##We need a for loop here as we must work backwards through the version collection
    for ($i = $versionCount;$i -gt 0;$i--)
    {
        $version = $versions[$i-1];
        write-host $version["Title"];
        write-host $version["Modified"];
        write-host $version["Editor"];
        write-host $version["Comments"];
        write-host $version.VersionId;
    
        $newItem["Title"] = $version["Title"];
        $newItem["Modified"] = $version["Modified"];
        $newItem["Editor"] = $version["Editor"];
        $newItem["Comments"] = $version["Comments"];
        $newItem.Update();
        
    }


    Please ensure that you mark a question as Answered once you receive a satisfactory response. This helps people in future when searching and helps prevent the same questions being asked multiple times.

    • Marked as answer by johnjohn11 Wednesday, December 2, 2015 12:39 AM
    Thursday, November 26, 2015 4:43 PM

All replies

  • Hi John,

    The first 4 items are relatively simple, you basically create the new list item and pass the original properties into the new list object to set them.

    The last bit is much harder to do and requires you to copy all of the versions of each list item as well. You then need to create each list item version by version, rebuilding the item as you go. The reason for this is due to the mechanism used by the Multi-line Text (Append) field type that is used to render comments from all of the previous versions of the object.

    Potentially, if it's acceptable to you/the client, then you could read all of the versions, then just create a single item with a concatenated Comments field containing the dates/comments from each of the versions. This field would then append onto this moving forward.

    Paul.


    Please ensure that you mark a question as Answered once you receive a satisfactory response. This helps people in future when searching and helps prevent the same questions being asked multiple times.

    Wednesday, November 25, 2015 2:48 PM
  • Hi John,

    The first 4 items are relatively simple, you basically create the new list item and pass the original properties into the new list object to set them.

    The last bit is much harder to do and requires you to copy all of the versions of each list item as well. You then need to create each list item version by version, rebuilding the item as you go. The reason for this is due to the mechanism used by the Multi-line Text (Append) field type that is used to render comments from all of the previous versions of the object.

    Potentially, if it's acceptable to you/the client, then you could read all of the versions, then just create a single item with a concatenated Comments field containing the dates/comments from each of the versions. This field would then append onto this moving forward.

    Paul.


    Please ensure that you mark a question as Answered once you receive a satisfactory response. This helps people in future when searching and helps prevent the same questions being asked multiple times.

    thanks for the reply, now i should have mentioned that i do not care about the item versions, since this is a new list , so we do not care how the item reached its final version...so i do not need to copy the versions.

    so let me summarize what u mentioned:-

    1. you mean now i can modify the created date, created by, modified date & modified by fields on the new list items to match the original items ? is this correct ? but can you adivce on the mechanize i can use to achieve this , for example using power-shell or i can do so from SP designer?

    2. second point i did not understand what u mean exactly by this sentence, can you adivce more on this :-

    Potentially, if it's acceptable to you/the client, then you could read all of the versions, then just create a single item with a concatenated Comments field containing the dates/comments from each of the versions. This field would then append onto this moving forward.

    Wednesday, November 25, 2015 4:15 PM
  • Hi John,

    To set the fields, you have to do it through PowerShell (I assumed that you're coding in some fashion as this is the dev forum 8-)), I don't believe it's possible through SPD.

    To set the created date in PowerShell, you can update the item metadata once it's been created..

    Pseudo code example:-

    $newItem = $list.items.add()
    
    $newItem["Title"] = "The title"
    
    $newItem["Created"] = $createdDatefromOriginal
    
    $newItem["Modified"] = $modifiedDateFromOriginal
    
    $newItem.update()

    As for not caring about the versions, you kind of have no choice if you want to add the timestamped comments into the new object. SharePoint uses the version functionality to store these comments. In the picture that you showed in your original post, the item in view would be version 3, the top comment would be coming from version 2 and the bottom comment from version 1.

    When SharePoint renders the list item, it understands that the comments field is set to append comments and it uses a special rendering template that fetches the field values from the other versions.

    So, if this information is critical and must be kept, you either have to re-create all of the versions, or you have to capture the comments from every version and then insert that into the new item's comments field. If you just copy the latest version, you will lose all of the previous comments.

    Hopefully that makes sense.

    Paul.


    Please ensure that you mark a question as Answered once you receive a satisfactory response. This helps people in future when searching and helps prevent the same questions being asked multiple times.

    Wednesday, November 25, 2015 4:42 PM
  • Hi John,

    To set the fields, you have to do it through PowerShell (I assumed that you're coding in some fashion as this is the dev forum 8-)), I don't believe it's possible through SPD.

    To set the created date in PowerShell, you can update the item metadata once it's been created..

    Pseudo code example:-

    $newItem = $list.items.add()
    
    $newItem["Title"] = "The title"
    
    $newItem["Created"] = $createdDatefromOriginal
    
    $newItem["Modified"] = $modifiedDateFromOriginal
    
    $newItem.update()

    As for not caring about the versions, you kind of have no choice if you want to add the timestamped comments into the new object. SharePoint uses the version functionality to store these comments. In the picture that you showed in your original post, the item in view would be version 3, the top comment would be coming from version 2 and the bottom comment from version 1.

    When SharePoint renders the list item, it understands that the comments field is set to append comments and it uses a special rendering template that fetches the field values from the other versions.

    So, if this information is critical and must be kept, you either have to re-create all of the versions, or you have to capture the comments from every version and then insert that into the new item's comments field. If you just copy the latest version, you will lose all of the previous comments.

    Hopefully that makes sense.

    Paul.


    Please ensure that you mark a question as Answered once you receive a satisfactory response. This helps people in future when searching and helps prevent the same questions being asked multiple times.

    ok then for the created + modified fields for the item i can update them using powershell. i will try your approach,, thanks.

    second point .. now for the comments , i can manually copy/paste the comments inside the new item (same as i will be doing for the items themselfs), of course this will generate new version for each item on the new list , which is fine.

    but the comments will have the created by and created date = to the user who will do the transfer and not equal to the original comments values. so can i using powershell update the comments' created by & created date fields to match the original values?


    • Edited by johnjohn11 Wednesday, November 25, 2015 5:14 PM
    Wednesday, November 25, 2015 5:12 PM
  • If all you're going to do is cut and paste the consolidated comments into the new item's comments field, then the date, time and author will come us part of that cut and paste.

    If you want to have the comments field behave exactly as it does in the current item, then you'll need to use PowerShell to work through the $item.versions object to get the comments.

    Personally, if you just want a record of the comments, I'd cut and paste them as once they're in the new comments field they'll be uneditable in future versions. You'll end up with something like:-

    PAULH 25/11/2015 Pasted copy of old comments

    OTHER 14/11/2015 Old copy of comments (this line is just part of the comment body)

    OTHER 12/11/2015 Old copy of older comments (same here)

    Paul.


    Please ensure that you mark a question as Answered once you receive a satisfactory response. This helps people in future when searching and helps prevent the same questions being asked multiple times.


    Wednesday, November 25, 2015 7:25 PM
  • If all you're going to do is cut and paste the consolidated comments into the new item's comments field, then the date, time and author will come us part of that cut and paste.

    If you want to have the comments field behave exactly as it does in the current item, then you'll need to use PowerShell to work through the $item.versions object to get the comments.

    Personally, if you just want a record of the comments, I'd cut and paste them as once they're in the new comments field they'll be uneditable in future versions. You'll end up with something like:-

    PAULH 25/11/2015 Pasted copy of old comments

    OTHER 14/11/2015 Old copy of comments (this line is just part of the comment body)

    OTHER 12/11/2015 Old copy of older comments (same here)

    Paul.


    Please ensure that you mark a question as Answered once you receive a satisfactory response. This helps people in future when searching and helps prevent the same questions being asked multiple times.


    thanks for the valuable reply . so you mean i can copy the comment text from the old item, then paste it inside the new list. in this case i will have the comment body being added correclty inside the new list, but with wrong username and date. then i can use powershell and through the $item.versions object to update the comment's created date and created by to match the original values ? is this what u meant in your reply ?

    second point . now we have an on premise deployment of SharePoint server 2013, so i have full access to everything. so i was thinking if i can copy/paste all the items and comments using the site administrator username... then i can access the database (instead of writing power-shell scripts) and update the item auto-generated info such as created date , created by, modified date and modified by... in addition to updating the comments create date and created by ? is this a valid approach ?

    thanks


    • Edited by johnjohn11 Thursday, November 26, 2015 12:35 PM
    Thursday, November 26, 2015 12:31 PM
  • First point: No I meant that if you cut and paste, the original date and username will be part of the body text, so you won't be able to change the modified and author using PowerShell. The ONLY way to keep the original comments with their original dates and authors is to rebuild the versions one by one in PowerShell so that they match the original item.

    On the second point.. DON'T EDIT THE DATABASE EVER!  Big text because this is critical for SharePoint.

    The only supported way to update anything in SharePoint is through the UI or the Object model via managed code/PowerShell. Editing the database is a short cut to removing any option of support from Microsoft and a guaranteed way to break your SharePoint farm.

    The only time you should edit the database is when instructed to do so by Microsoft as a result of a service call.

    Paul.


    Please ensure that you mark a question as Answered once you receive a satisfactory response. This helps people in future when searching and helps prevent the same questions being asked multiple times.

    Thursday, November 26, 2015 1:28 PM
  • First point: No I meant that if you cut and paste, the original date and username will be part of the body text, so you won't be able to change the modified and author using PowerShell. The ONLY way to keep the original comments with their original dates and authors is to rebuild the versions one by one in PowerShell so that they match the original item.

    On the second point.. DON'T EDIT THE DATABASE EVER!  Big text because this is critical for SharePoint.

    The only supported way to update anything in SharePoint is through the UI or the Object model via managed code/PowerShell. Editing the database is a short cut to removing any option of support from Microsoft and a guaranteed way to break your SharePoint farm.

    The only time you should edit the database is when instructed to do so by Microsoft as a result of a service call.

    Paul.


    Please ensure that you mark a question as Answered once you receive a satisfactory response. This helps people in future when searching and helps prevent the same questions being asked multiple times.

    Ok i got your point, now i tried this script and i was able to modify the; created,modified, created by and modified by fields for an item with title ="test tiltle" and it did not generate a new version which is perfect.

    #set the web url and the list name to work upon
    $url = "http://**/Customer Sites/customerA/"
    $listName = "Action"
    $fileName = "test title"
     
    #Get the appropriate list from the web
    $web = get-SPWeb $url
    $list = $web.lists[$listName]
     
    #Get the file using the filename
    $item = $list.Items | ? {$_.Title -eq $fileName}
     
    #Print out current Created by and Created date
    Write-Output ("item created by {0} on {1}" -f $item["Author"].tostring(), $item["Created"] )
     
    #Print out current Created by and Created date
    Write-Output ("item last modified by {0} on {1}" -f $item["Editor"].tostring(), ($item["Modified"] -f "dd-MM-yyyy"))
     
    #Set the created by values
    $userLogin = "ad-t**\***.***"
    $dateToStore = Get-Date "10/02/2015 10:15:20"
    $dateToStore2 = Get-Date "12/02/2015 23:15:20"
     
    $user = Get-SPUser -Web $web | ? {$_.userlogin -eq $userLogin}
    $userString = "{0};#{1}" -f $user.ID, $user.UserLogin.Tostring()
     
     
    #Sets the created by field
    $item["Author"] = $userString
    $item["Created"] = $dateToStore
     
    #Set the modified by values
    $item["Editor"] = $userString
    $item["Modified"] = $dateToStore2
     
     
    #Store changes without overwriting the existing Modified details.
    $item.UpdateOverwriteVersion()

    so my question now if i can use similar approach to update or create the items comments ? can you advice on this please ?

    Thursday, November 26, 2015 2:22 PM
  • The quick answer is yes you could... but it's quite convoluted.

    Let me show you what cut and paste looks like first, as this might be suitable for your needs, then I'll show you how to get the version..

    As you can see, if you cut and paste the comments into a new item, it concatenates the text into one entry. So when you go and edit this item in future, the new comments become additional items.

    If that's not suitable, then you'll need to rebuild the list item from scratch from the original set of versions. I'll do that in the next reply as this editor pane is tiny!

    Paul.


    Please ensure that you mark a question as Answered once you receive a satisfactory response. This helps people in future when searching and helps prevent the same questions being asked multiple times.

    Thursday, November 26, 2015 4:29 PM
  • Ok, so this little snippet of PowerShell should show you how to extract the version information from a list item, then in reverse build up a new item in the same list with the same version history.

    Hope this helps

    Paul.

    $web = get-spweb http://escdemos
    $list = $web.lists["VersionTest"]
    $sourceItem = $list.items.GetItemById(1)
    
    $versions = $sourceItem.versions
    
    $newItem = $list.items.Add();
    
    $versionCount = $versions.Count;
    
    ##We need a for loop here as we must work backwards through the version collection
    for ($i = $versionCount;$i -gt 0;$i--)
    {
        $version = $versions[$i-1];
        write-host $version["Title"];
        write-host $version["Modified"];
        write-host $version["Editor"];
        write-host $version["Comments"];
        write-host $version.VersionId;
    
        $newItem["Title"] = $version["Title"];
        $newItem["Modified"] = $version["Modified"];
        $newItem["Editor"] = $version["Editor"];
        $newItem["Comments"] = $version["Comments"];
        $newItem.Update();
        
    }


    Please ensure that you mark a question as Answered once you receive a satisfactory response. This helps people in future when searching and helps prevent the same questions being asked multiple times.

    • Marked as answer by johnjohn11 Wednesday, December 2, 2015 12:39 AM
    Thursday, November 26, 2015 4:43 PM
  • Ok, so this little snippet of PowerShell should show you how to extract the version information from a list item, then in reverse build up a new item in the same list with the same version history.

    Hope this helps

    Paul.

    $web = get-spweb http://escdemos
    $list = $web.lists["VersionTest"]
    $sourceItem = $list.items.GetItemById(1)
    
    $versions = $sourceItem.versions
    
    $newItem = $list.items.Add();
    
    $versionCount = $versions.Count;
    
    ##We need a for loop here as we must work backwards through the version collection
    for ($i = $versionCount;$i -gt 0;$i--)
    {
        $version = $versions[$i-1];
        write-host $version["Title"];
        write-host $version["Modified"];
        write-host $version["Editor"];
        write-host $version["Comments"];
        write-host $version.VersionId;
    
        $newItem["Title"] = $version["Title"];
        $newItem["Modified"] = $version["Modified"];
        $newItem["Editor"] = $version["Editor"];
        $newItem["Comments"] = $version["Comments"];
        $newItem.Update();
        
    }


    Please ensure that you mark a question as Answered once you receive a satisfactory response. This helps people in future when searching and helps prevent the same questions being asked multiple times.

    now i tried this approach to update the Editor & Modified date for an existing comment :-

    #set the web url and the list name to work upon
    $url = "http://***/Customer Sites/customerA/"
    $listName = "Action"
    $fileName = "12312312"
     
    #Get the appropriate list from the web
    $web = get-SPWeb $url
    $list = $web.lists[$listName]
     
    #Get the file using the filename
    $item = $list.Items | ? {$_.Title -eq $fileName}
    $versions = $item.versions 
    $version = $versions[0];
    
     
    #Set the created by values
    $userLogin = "a***\m***"
    $dateToStore = Get-Date "10/03/2015 10:15:20"
    $dateToStore2 = Get-Date "12/03/2015 23:15:20"
     
    $user = Get-SPUser -Web $web | ? {$_.userlogin -eq $userLogin}
    $userString = "{0};#{1}" -f $user.ID, $user.UserLogin.Tostring()
     
     
    
    
     
    #Set the modified by values
    $version["Editor"] = $userString
    $version["Modified"] = $dateToStore2
     
     
    #Store changes without overwriting the existing Modified details.
    $item.UpdateOverwriteVersion()

    but i got the following exception on these two statements:-

    $version["Editor"] = $userString
    $version["Modified"] = $dateToStore2

    :-

    Unable to index into an object of type Microsoft.SharePoint.SPListItemVersion.
    At line:1 char:1

    here is a screen of my powershell :-

    so can you adivce on this please ?

    Friday, November 27, 2015 1:31 AM
  • You can't update a Version as it's a read only item (That's the idea of a version, it's an immutable object that cannot be changed for audit reasons). That's why you have to rebuild the item history from scratch using the method I showed you previously.

    Paul.


    Please ensure that you mark a question as Answered once you receive a satisfactory response. This helps people in future when searching and helps prevent the same questions being asked multiple times.

    Friday, November 27, 2015 9:30 AM
  • You can't update a Version as it's a read only item (That's the idea of a version, it's an immutable object that cannot be changed for audit reasons). That's why you have to rebuild the item history from scratch using the method I showed you previously.

    Paul.


    Please ensure that you mark a question as Answered once you receive a satisfactory response. This helps people in future when searching and helps prevent the same questions being asked multiple times.

    Thanks again for your helpful information. so let me summarize my questions:-

    1. You mean if i create a comment manually , I will not be able to update its info such as created & created by ?

    2. but seems i can update these info for the item itself which will automatically apply to the first comment, as the first comment of each item will equal to the item modified date, but SP does not allow doing the same for the item version > 1?

    3. in your example you are creating a new item and update its version. but in my case i prefer to add a new version using power-shell to existing item, by passing these info ; created date, created by +comment  ? is this possible ?

    Thanks

    Friday, November 27, 2015 12:27 PM
  • You can always update the current Major version of an item using the methods in the PowerShell script, but the older versions cannot be changed (The ones access through the SPListItem.Versions collection)

    In the example I showed you, I'm not adding the versions as that isn't possible, I'm creating a new item over the top each time, thus building the item history in the same way it would be created by a human creating and modifying a list item.

    E.g. the first time my script loops, it creates the list item using the information from the first version (This would be the original list item creation), the second loop updates the list item with the metadata of the second version (This would be the first modification of the original list item), the final loop updates the list item with the metadata of the currently published version. By using this method you effectively rebuild the item version hisotyr from the ground up, but with the original date/time and author information.

    Just to be clear, you cannot create a copy of the current major version and then add the old versions to it.. It's not possible.

    Paul.


    Please ensure that you mark a question as Answered once you receive a satisfactory response. This helps people in future when searching and helps prevent the same questions being asked multiple times.

    Friday, November 27, 2015 5:00 PM
  • You can always update the current Major version of an item using the methods in the PowerShell script, but the older versions cannot be changed (The ones access through the SPListItem.Versions collection)

    In the example I showed you, I'm not adding the versions as that isn't possible, I'm creating a new item over the top each time, thus building the item history in the same way it would be created by a human creating and modifying a list item.

    E.g. the first time my script loops, it creates the list item using the information from the first version (This would be the original list item creation), the second loop updates the list item with the metadata of the second version (This would be the first modification of the original list item), the final loop updates the list item with the metadata of the currently published version. By using this method you effectively rebuild the item version hisotyr from the ground up, but with the original date/time and author information.

    Just to be clear, you cannot create a copy of the current major version and then add the old versions to it.. It's not possible.

    Paul.


    Please ensure that you mark a question as Answered once you receive a satisfactory response. This helps people in future when searching and helps prevent the same questions being asked multiple times.

    ok i got your point sound a very helpful approach , thanks very much. but now your original code is as follow:-

    $web = get-spweb http://escdemos
    $list = $web.lists["VersionTest"]
    $sourceItem = $list.items.GetItemById(1)
    
    $versions = $sourceItem.versions
    
    $newItem = $list.items.Add();
    
    $versionCount = $versions.Count;
    
    ##We need a for loop here as we must work backwards through the version collection
    for ($i = $versionCount;$i -gt 0;$i--)
    {
        $version = $versions[$i-1];
        write-host $version["Title"];
        write-host $version["Modified"];
        write-host $version["Editor"];
        write-host $version["Comments"];
        write-host $version.VersionId;
    
        $newItem["Title"] = $version["Title"];
        $newItem["Modified"] = $version["Modified"];
        $newItem["Editor"] = $version["Editor"];
        $newItem["Comments"] = $version["Comments"];
        $newItem.Update();
        
    }

    now i need to do the following modifications to it , is this correct ? :-

    1. Instead of creating a new item inside the same list, i need to modify the script to create the new item on our new list , is this correct ?

    2. second point , i was planning to manually copy/paste the item content such as title, description , etc... but in your script i will be adding the new item using power-shell. so in this case i need to mention all my item fields inside the script is this correct ? , mainly  AS FOLLOW:-

    $newItem["Title"] = $version["Title"]; $newItem["Modified"] = $version["Modified"]; $newItem["Editor"] = $version["Editor"]; $newItem["Comments"] = $version["Comments"];

    ## i need to add all the fields here ... $newItem["MYFIELD1"] = $version["MYFIELD1"]; $newItem["MYFIELD2"] = $version["MYFIELD2"]; $newItem.Update();


    3. Third question, now i have the description field of type enhanced rich text editor , which might have images and hyperlinks, so will i be able to assign its value as follow :-

     $newItem["Description"] = $version["Description"];

    4. finally do i need to use the fields display names or i can use the fields internal names when referencing my fields ? as i have many fields that have the same display name ..

    thanks




    • Edited by johnjohn11 Friday, November 27, 2015 5:59 PM
    Friday, November 27, 2015 5:56 PM
  • Hi John,

    Almost there I think! 8-)

    1. Yes, my sample was just for brevity.. I'd use two PowerShell variables, SourceList and TargetList. You just need to ensure that both lists are configured with the same field types. (And they have to be in the same site collection! This is because of how the Editor and Author fields work.. the lookup values in these are specific to the site collection)

    2. Do it all in PowerShell, otherwise you have to set the metadata afterwards.. Put your fields in exactly where you've shown, they should copy like for like using that method. (Are you using any lookup fields? In theory that should work but I'd test if you are.)

    3. Yes, the text is just stored differently inside it. Plain text just stores the strings where as Rich text stores markup like <p>text</p>. It all copies the same way.

    4. You need to use the internal names. You can get these through the browser by editing the column and looking for fieldname in the URL, or through PowerShell ($list.fields | select internalname)

    Paul.


    Please ensure that you mark a question as Answered once you receive a satisfactory response. This helps people in future when searching and helps prevent the same questions being asked multiple times.

    Saturday, November 28, 2015 7:33 AM
  • ok thanks again for your reply.i tried this script :-

    $web = get-spweb "****"
    $list = $web.lists["Action"]
    $list2 = $web.lists["Risk Issue"]
    $sourceItem = $list.items.GetItemById(1)
    
    $versions = $sourceItem.versions
    
    $newItem = $list2.items.Add();
    
    $versionCount = $versions.Count;
    
    ##We need a for loop here as we must work backwards through the version collection
    for ($i = $versionCount;$i -gt 0;$i--)
    {
        $version = $versions[$i-1];
        write-host $version["Title"];
        write-host $version["Modified"];
        write-host $version["Editor"];
        write-host $version["Comments"];
        write-host $version.VersionId;
    
        $newItem["Title"] = $version["Title"];
        $newItem["Modified"] = $version["Modified"];
        $newItem["Editor"] = $version["Editor"];
        $newItem["Author"] = $version["Author"];
        $newItem["Created"] = $version["Created"];
        $newItem["Comment"] = $version["Comment"];
        $newItem["Comments"] = $version["Comments"];
    
        $newItem["Risk_x0020_or_x0020_Issue"] = $version["Action_x002F_Issue_x002F_Project"];
        $newItem["Area"] = $version["Action_x0020_Area"];
        $newItem["RiskIssue_x0020_Owner"] = $version["T_x0020_Owner"];
        $newItem["Date_x0020_Reported"] = $version["Date_x0020_Reported"];
        $newItem["Customer_x0020_Risk_x002f_Issue_"] = $version["Customer_x0020__x0020_Owner"];
        $newItem["Risk_x002F_Issue_x0020_status"] = $version["Action_x0020_Status"];
        
        
        $newItem.Update();
        
    }

    ... and i was able to move items from a list named "Action" to a list named "Risk Issue". But i have the following question which was raised during my test:-


    1. Inside this Link they mentioned that using item.Update() will create new version and will update the modified & modified by fields.

    But from my test this is not correct, as inside my above power-shell script i did not get any extra version and the modified date and modified by fields will be = to the original item, although i am using $newitem.Update().

    so could the reason behind this is that we are creating a new item inside the above power shell script ,, so using item.Update will not add extra version and will not modify the modified and modified by fields? while if i am retrieving an existing item , then i call item.Update() this will cause a new version to be created and the modified date & modified by will get updated as mentioned on the link ?

    thanks






    • Edited by johnjohn11 Monday, November 30, 2015 6:38 PM
    Monday, November 30, 2015 3:34 PM
  • 1. Inside this Link they mentioned that using item.Update() will create new version and will update the modified & modified by fields.

    But from my test this is not correct, as inside my above power-shell script i did not get any extra version and the modified date and modified by fields will be = to the original item, although i am using $newitem.Update().

    so could the reason behind this is that we are creating a new item inside the above power shell script ,, so using item.Update will not add extra version and will not modify the modified and modified by fields? while if i am retrieving an existing item , then i call item.Update() this will cause a new version to be created and the modified date & modified by will get updated as mentioned on the link ?

    thanks

    I'm not sure I'm clear on what you're asking here? We have to use the $newitem.update() as we must create a new version in order to build up the version history, however because we are directly modifying the "Author" and "Modified" fields, these values are used rather than assigning new values.

    If we were to use systemupdate or updateoverwritenewversion, then the version history wouldn't get created and our append fields wouldn't work.

    Paul.


    Please ensure that you mark a question as Answered once you receive a satisfactory response. This helps people in future when searching and helps prevent the same questions being asked multiple times.

    Tuesday, December 1, 2015 4:04 PM
  • 1. Inside this Link they mentioned that using item.Update() will create new version and will update the modified & modified by fields.

    But from my test this is not correct, as inside my above power-shell script i did not get any extra version and the modified date and modified by fields will be = to the original item, although i am using $newitem.Update().

    so could the reason behind this is that we are creating a new item inside the above power shell script ,, so using item.Update will not add extra version and will not modify the modified and modified by fields? while if i am retrieving an existing item , then i call item.Update() this will cause a new version to be created and the modified date & modified by will get updated as mentioned on the link ?

    thanks

    I'm not sure I'm clear on what you're asking here? We have to use the $newitem.update() as we must create a new version in order to build up the version history, however because we are directly modifying the "Author" and "Modified" fields, these values are used rather than assigning new values.

    If we were to use systemupdate or updateoverwritenewversion, then the version history wouldn't get created and our append fields wouldn't work.

    Paul.


    Please ensure that you mark a question as Answered once you receive a satisfactory response. This helps people in future when searching and helps prevent the same questions being asked multiple times.


    yes but i though that using item.Update() will create an additional version as a result of running the script,, but seems it will not create additional version and it will copy the exact number of versions as defined inside the source items,, this is my question ...

    • Edited by johnjohn11 Tuesday, December 1, 2015 7:30 PM
    Tuesday, December 1, 2015 6:28 PM
  • The script should create an exact copy of the source list item.. e.g. if the source item has 5 versions, then the target item should have 5 versions with identical metadata, that's how it's working on my test machine.

    What's happening in your target list? Is it just creating a single item with no versions? if so, check you've got versioning turned on in the target list.

    Paul.


    Please ensure that you mark a question as Answered once you receive a satisfactory response. This helps people in future when searching and helps prevent the same questions being asked multiple times.

    Tuesday, December 1, 2015 10:50 PM
  • The script should create an exact copy of the source list item.. e.g. if the source item has 5 versions, then the target item should have 5 versions with identical metadata, that's how it's working on my test machine.

    What's happening in your target list? Is it just creating a single item with no versions? if so, check you've got versioning turned on in the target list.

    Paul.


    Please ensure that you mark a question as Answered once you receive a satisfactory response. This helps people in future when searching and helps prevent the same questions being asked multiple times.

    on my machine it also create the exact number of version as on the source item, which is correct. but my concern was that using item.Update() should create additional version ,, this is mentioned inside the link i provided,, but on our script no new version was created . so let say the source item have 4 versions, and i run the script then i thought that the new item will have 5 version since i am using item.Update() ,,, but on real 4 versions were created. which is fine. hope you get my point ?

    Second question which i have regarding your script, should i use the internal names of the site columns as they are defined inside the list level Or as they are defined inside their site level. for example i found that the build-in site column named "Due Date" have its internal names at the site level as "TaskDueDate" while its internal name at the list level is "DueDate" ? also i i have a custom site column that have its internal name as "Technical_x0020_Delivery_x0020_Team" on the site level, while its internal name at the list level is "Technical_x0020_Delivery_x0020_T"  , so which one i should use. now i am a bit confused as on some cases i was able to reference the site columns using their internal names at the site level, while on other cases i have to use their list level internal names,, so is there any rule to follow ?

    Here my test, for 3 columns:-

    1) First Column have its internal name at the list level = "DueDate", while at the site level its internal name = "TaskDueDate".

    2) Second Column have its internal name at the list level = "Technical_x0020_Delivery_x0020_T", while at the site level its internal name = "Technical_x0020_Delivery_x0020_Team".

    3) Third Column  have its internal name at the list level  = Software_x0020_Development_x0020, while at the site level its internal name = Software_x0020_Development_x0020_Risk_x002F_Issue_x0020_Owner

    now on the first and third site columns i was NOT able to reference the columns using their site level internal names as follow, as i will get an error that powershell can not find these columns

    $newItem["TaskDueDate"] 

    &

    $newItem["Software_x0020_Development_x0020_Risk_x002F_Issue_x0020_Owner"]

    and i have to use their internal names as defined inside the list level, so this will work well:-

    $newItem["DueDate"] 

    &

    $newItem["Software_x0020_Development_x0020"

    while for the second column i was able to reference it either using its site level or list level internal names? so can you adivce what is the rule that govern this ?



    • Edited by johnjohn11 Wednesday, December 2, 2015 1:28 AM
    Wednesday, December 2, 2015 12:28 AM
  • Hi there,

    The .Update() is working exactly as intended, basically each time we call it, it's creating a version, which as we're rebuilding the item from the ground up means the number of versions should match.

    For the column names, you should use the List internal names only.

    You can get these through Powershell:-

    $list.fields | select title ,internalname
    

    Paul.

    Please ensure that you mark a question as Answered once you receive a satisfactory response. This helps people in future when searching and helps prevent the same questions being asked multiple times.

    Wednesday, December 2, 2015 9:31 AM
  • Hi there,

    The .Update() is working exactly as intended, basically each time we call it, it's creating a version, which as we're rebuilding the item from the ground up means the number of versions should match.

    For the column names, you should use the List internal names only.

    You can get these through Powershell:-

    $list.fields | select title ,internalname

    Paul.

    Please ensure that you mark a question as Answered once you receive a satisfactory response. This helps people in future when searching and helps prevent the same questions being asked multiple times.

    thanks for the reply again..

    >>The .Update() is working exactly as intended, basically each time we call it, it's creating a version, which as we're >>rebuilding the item from the ground up means the number of versions should match.

    OK i got your point

    >>For the column names, you should use the List internal names only.

    OK i will do , but i am a bit confused as on some columns i was able to use their internal names as defined inside the site level, although they have different internal names at the list level.. while for other columns using their site level internal names did not work ... so can you adivce what is the rule that govern this ?

    Wednesday, December 2, 2015 12:40 PM
  • As far as I'm aware you should only use the internal names as presented by the list. When you have site columns and add them to a list, they actually get created as an instance of the site column within the list definition.

    I've only ever used the internal name as presented by the list object ($list.fields) and never hit an issue.

    Paul.


    Please ensure that you mark a question as Answered once you receive a satisfactory response. This helps people in future when searching and helps prevent the same questions being asked multiple times.

    Wednesday, December 2, 2015 1:03 PM
  • As far as I'm aware you should only use the internal names as presented by the list. When you have site columns and add them to a list, they actually get created as an instance of the site column within the list definition.

    I've only ever used the internal name as presented by the list object ($list.fields) and never hit an issue.

    Paul.


    Please ensure that you mark a question as Answered once you receive a satisfactory response. This helps people in future when searching and helps prevent the same questions being asked multiple times.

    but do u have any idea why SharePoint allow using Internal names for some site columns as defined inside the site level , while it doesn't allow for other site columns ?.. although in both cases the site columns have different internal names at the site level and at the list level ...

    • Edited by johnjohn11 Wednesday, December 2, 2015 5:52 PM
    Wednesday, December 2, 2015 5:52 PM
  • I'm going to hazard a guess that the name get's shortened somehow in the process of addressing it.. but I can't back that up with evidence..

    The rule of thumb is, always use the list field internal name as that is the instance of the field that you're playing with.

    Paul.


    Please ensure that you mark a question as Answered once you receive a satisfactory response. This helps people in future when searching and helps prevent the same questions being asked multiple times.

    Thursday, December 3, 2015 11:10 AM
  • I'm going to hazard a guess that the name get's shortened somehow in the process of addressing it.. but I can't back that up with evidence..

    The rule of thumb is, always use the list field internal name as that is the instance of the field that you're playing with.

    Paul.


    Please ensure that you mark a question as Answered once you receive a satisfactory response. This helps people in future when searching and helps prevent the same questions being asked multiple times.


    ok thanks for your help ,, it worked well
    Thursday, December 3, 2015 5:21 PM