1

I'm trying to write a script that will unarchive a list item from a sql database archive. The data is going back to the same list that it was in originally so the fields are all matched up. I'd like to be able to put the item back in with the same ID, so lookups in other lists aren't broken. I'd done some research and it seems that others have had success by setting the ID field to readonlyfield = false but I haven't been able to manage it.

  $lstStudents = $web.Lists["Students"]
  $lstStudents.Fields["ID"].ReadonlyField = $false
  $lstStudents.update()

Completes without any errors, but the ID of the item when I run the rest of the script doesn't keep the desired ID. Furthermore, when I check the value of $lstStudents.Fields["ID"].ReadonlyField it still says true.

Any ideas appreciated.

1 Answer 1

1

I'm pretty certain that you cannot change the ID. It is auto assigned. If you want to maintain your own ID, you will need to add a custom column to the list.

That said, there's sample C# code here (List item with specific ID value) that says you can update the ID field from the list.Fields[SPBuiltInFieldId.ID] property.

2
  • I've been playing around with this code and it seems like I can set an arbitrary ID in a C# console application but not in Powershell. In fact, if I run the code you linked to but comment out the line "list.Fields[SPBuiltInFieldId.ID].ReadOnlyField = true;" and look at the $list["ID"] field, it still shows as ReadOnlyField = true. I'm guessing that somehow the SPBuiltInFieldId.ID is somehow different from indexing the fields. It's very weird. Still looking for a way to access [SPBuiltInFieldId.ID] from powershell Commented Nov 16, 2018 at 14:50
  • SPBuiltInFieldId.ID is defined in Microsoft.SharePoint.dll as public static readonly Guid ID = new Guid("{1d22ea11-1e32-424e-89ab-9fedbadb6ce1}"); - don't know (yet) if it works using the GUID as string, just putting it here because we are currently trying to do the same (in SPO) :p Commented Feb 11, 2022 at 11:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.