pnp / PnP-PowerShell

SharePoint PnP PowerShell CmdLets
https://pnp.github.io/powershell
Other
987 stars 665 forks source link

Add-PnPDataRowsToProvisioningTemplate : Microsoft.SharePoint.Client.ServerException: User cannot be found. #2651

Open PedroMordeP opened 4 years ago

PedroMordeP commented 4 years ago

Reporting an Issue

Using Add-PnPDataRowsToProvisioningTemplate to add to the template xml the content of a list with a field of type "Person / Group":

<pnp:DataValue FieldName="TargetUsers">i:0#.f|membership|test@test.onmicrosoft.com</pnp:DataValue>

What can I do to fix this? is something on my Group?

Expected behavior

Should add to that field the group ? or the user inside that group?

Actual behavior

When trying to add the data it gives and error "Microsoft.SharePoint.Client.ServerException: User cannot be found"

Microsoft.SharePoint.Client.ServerException: User cannot be found.
   at Microsoft.SharePoint.Client.ClientRequest.ProcessResponseStream(Stream responseStream)
   at Microsoft.SharePoint.Client.ClientRequest.ProcessResponse()
   at Microsoft.SharePoint.Client.ClientRequest.<ExecuteQueryToServerAsync>d__6.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.SharePoint.Client.ClientRequest.<ExecuteQueryAsync>d__0.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.SharePoint.Client.ClientRuntimeContext.<ExecuteQueryAsync>d__0.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.SharePoint.Client.ClientContext.<ExecuteQueryAsync>d__4.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.SharePoint.Client.ClientContextExtensions.<ExecuteQueryImplementation>d__7.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.SharePoint.Client.ClientContextExtensions.ExecuteQueryRetry(ClientRuntimeContext clientContext, Int32 retryCount, Int32 delay, String userAgent)
   at SharePointPnP.PowerShell.Commands.Provisioning.Site.AddDataRowsToProvisioningTemplate.GetLoginName(Web web, Int32 userId)
   at SharePointPnP.PowerShell.Commands.Provisioning.Site.AddDataRowsToProvisioningTemplate.<>c__DisplayClass9_0.<GetFieldValueAsText>b__1(FieldUserValue lv)
   at System.Linq.Enumerable.WhereSelectArrayIterator`2.MoveNext()
   at System.String.Join(String separator, IEnumerable`1 values)
   at SharePointPnP.PowerShell.Commands.Provisioning.Site.AddDataRowsToProvisioningTemplate.GetFieldValueAsText(Web web, ListItem listItem, Field field)
   at SharePointPnP.PowerShell.Commands.Provisioning.Site.AddDataRowsToProvisioningTemplate.ExecuteCmdlet()
   at SharePointPnP.PowerShell.Commands.PnPCmdlet.ProcessRecord()

Steps to reproduce behavior

Have a list with a field of type "Person or Group" Add to that field a Group Using Add-PnPDataRowsToProvisioningTemplate to add data rows to the XML

Which version of the PnP-PowerShell Cmdlets are you using?

What is the version of the Cmdlet module you are running?

PnP PowerShell for SharePoint Online 3.20.2004.0 or other below

How did you install the PnP-PowerShell Cmdlets?

ghost commented 4 years ago

Thank you for reporting this issue. We will be triaging your incoming issue as soon as possible.

kadu-jr commented 4 years ago

Hey @PedroMordeP,

I just found out you can actually insert the group id in the field parameter and it works! I was able to populate my People field with my 'Site Members' group that way. If you don't know your group's id, you can go to Site Settings > People and Groups. Once you select a group, you can see the parameter MembershipGroupId= in the browser's URL. Take that id and put it inside your DataValue tag and you should be fine.

I don't know if this behavior is intended or not, and I believe it could still be improved, though.

Funny enough, I think i stumbled on another bug while trying to debug yours. If I use the 'Add-PnPDataRowsToProvisioningTemplate' on a list that has a People field, I get an error. Something like 'the property has not been initialized'. Can you confirm if you are having this issue, too? I am on the latest release btw.

Let me know if you need any help.

PedroMordeP commented 4 years ago

Thank you for the test and the result, I will test it too with the ID but if I apply the template on a different tenant the id will not be the same!! So I wanted to use only the name, not sure if this will be possible.

About the 'the property has not been initialized' didn't get this error on my tests.