pnpframework icon indicating copy to clipboard operation
pnpframework copied to clipboard

Updating a field "_dlc_DocId" giving 'Access id denied'

Open PedroMordeP opened this issue 2 years ago • 1 comments

I'm applying a template and when is on SiteFields updating the field "_dlc_DocId" (ae3e2a36-125d-45d3-9051-744b513536a6) is giving "Access is denied"

This internal field should be updated? How can I validate if this field can be updated or skipped?

The differences between fields are attributes Version="2" and the SourceID="1234567890", and is only updating the field because of this. I changed the code to remove the attribute "Version" for the "equalityComparer" between them to skip but since the SourceID is also different, is trying to update the field attributes. How can I validate for skipping this kind of field?

Instead of throwing an exception for this when giving "access is denied" should I validate the type of error and show a warning?

Field from SharePoint <Field ID="{ae3e2a36-125d-45d3-9051-744b513536a6}" Type="Text" DisplayName="Document ID Value" Name="_dlc_DocId" Required="FALSE" ReadOnly="TRUE" Sealed="TRUE" Description="The value of the document ID assigned to this item." ShowInDisplayForm="FALSE" ShowInListSettings="FALSE" ShowInVersionHistory="FALSE" ShowInViewForms="FALSE" Indexed="TRUE" SourceID="{7e779ff5-6db1-4f4d-867e-3c32d1ace633}" StaticName="_dlc_DocId" Version="2" />

Fields from Template <Field ID="{ae3e2a36-125d-45d3-9051-744b513536a6}" Type="Text" DisplayName="Document ID Value" Name="_dlc_DocId" Required="FALSE" ReadOnly="TRUE" Sealed="TRUE" Description="The value of the document ID assigned to this item." ShowInDisplayForm="FALSE" ShowInListSettings="FALSE" ShowInVersionHistory="FALSE" ShowInViewForms="FALSE" Indexed="TRUE" SourceID="{4a5d4f64-1d82-4af9-98a5-6e5680abc5e6}" StaticName="_dlc_DocId" />

Exception given

Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED)) | Reason: (ServerUnauthorizedAccessException) Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED)) --- StackTrace: at Microsoft.SharePoint.Client.ClientRequest.ProcessResponseStream(Stream responseStream) at Microsoft.SharePoint.Client.ClientRequest.ProcessResponse() at Microsoft.SharePoint.Client.ClientRequest.ExecuteQueryToServerAsync(ChunkStringBuilder sb) at Microsoft.SharePoint.Client.ClientRequest.ExecuteQueryAsync() at Microsoft.SharePoint.Client.ClientRuntimeContext.ExecuteQueryAsync() at Microsoft.SharePoint.Client.ClientContext.ExecuteQueryAsync() at Microsoft.SharePoint.Client.ClientContextExtensions.ExecuteQueryImplementation(ClientRuntimeContext clientContext, Int32 retryCount, String userAgent) at Microsoft.SharePoint.Client.ClientContextExtensions.ExecuteQueryRetry(ClientRuntimeContext clientContext, Int32 retryCount, String userAgent) at PnP.Framework.Provisioning.ObjectHandlers.ObjectField.UpdateField(Web web, String fieldId, XElement templateFieldElement, PnPMonitoredScope scope, TokenParser parser, String originalFieldXml) at PnP.Framework.Provisioning.ObjectHandlers.ObjectField.ProvisionObjects(Web web, ProvisioningTemplate template, TokenParser parser, ProvisioningTemplateApplyingInformation applyingInformation) at PnP.Framework.Provisioning.ObjectHandlers.SiteToTemplateConversion.ApplyRemoteTemplate(Web web, ProvisioningTemplate template, ProvisioningTemplateApplyingInformation provisioningInfo, Boolean calledFromHierarchy, TokenParser tokenParser)

PedroMordeP avatar Apr 18 '23 11:04 PedroMordeP

I end up getting the "Sealed" property of the existing field to check if I can update it.

web.Context.Load(existingField, f => f.SchemaXml, f => f.Sealed);

Hope this is the better solution

PedroMordeP avatar Apr 18 '23 16:04 PedroMordeP