Hello,
I have been looking into this forum about how to insert an List Item with a specific Id or Update an item with a specific ID field?
Then I have found some properties to be updated like AllowUnsafeUpdates and set ReadOnly to false in the ID column.
So, I have made some scripts in powershell, but it does not work.
This is the code to allow unsafe updates in the site a site collection
Add-PSSnapin Microsoft.Sharepoint.Powershell
$SPSite = Get-SPSite -Identity "******"
$SPWeb = Get-SPWeb -Identity "******"
Write-Host -ForegroundColor Gray $SPWeb.Url":"
$AllowUnsafeUpdatesStatus = $SPWeb.AllowUnsafeUpdates
Write-Host -ForegroundColor Red " The current value for web is " $SPWeb.AllowUnsafeUpdates
Write-Host -ForegroundColor Red " The current value for site is " $SPSite.AllowUnsafeUpdates
$SPSite.AllowUnsafeUpdates = $true
$SPWeb.AllowUnsafeUpdates = $true
$SPList = $SPWeb.Lists.TryGetList("******")
$SPFieldID = $SPList.Fields.GetFieldByInternalName("ID")
#$SPFieldID.Update()
#$SPList.Update()
Write-Host -ForegroundColor Green " The new value for site is " $SPSite.AllowUnsafeUpdates
#Dispose the SPWeb object
$SPWeb.Dispose()
$SPSite.Dispose()
Then, with Javascript I have updated the column to readonly
var clientContext = new SP.ClientContext(_spPageContextInfo.webAbsoluteUrl);
var webSite = clientContext.get_web();
var field = webSite.getList(_spPageContextInfo.webAbsoluteUrl + "/Lists/*****").get_fields().getByInternalNameOrTitle("ID");
field.set_readOnlyField(false);
field.update();
clientContext.load(field);
clientContext.executeQueryAsync(Function.createDelegate(this, function () {
console.log(field.get_readOnlyField());
}), Function.createDelegate(this, function (sender, args) {
console.error('Request failed. ' + args.get_message() + '\n' + args.get_stackTrace());
}));Then, I have tried to insert the item with an specific Id, but I got this error message:
This field cannot be updated.
Thank you!