powershell icon indicating copy to clipboard operation
powershell copied to clipboard

[BUG] - Add/Set-PnPListItem with managed metada / taxonomy field value failed on a batch request

Open lfreyss opened this issue 5 years ago • 8 comments

Hello,

Reporting an Issue or Missing Feature

I think I've an issue with Add-PnPListItem/Set-PnPListItem when I want to create an item with a taxonomy field on a batch request. Work great without the batch parameter and work great with batch or without if I don't add the taxonomy field.

Expected behavior

Created multiple items in my SP List in batch with the associated values for each of my field

Actual behavior

Error when trying to add the request in the batch process (even before the cmd Invoke-PnPBatch -Batch $batch)

Add-PnPListItem: Object reference not set to an instance of an object.

Get-PnPException

Message : Object reference not set to an instance of an object. Stacktrace : at PnP.PowerShell.Commands.Utilities.ListItemHelper.GetFieldValues(IList list, IListItem existingItem, Hashtable valuesToSet, ClientContext clientContext, PnPBatch
batch) in c:\PnPPowerShell\src\Commands\Utilities\ListItemHelper.cs:line 464 at PnP.PowerShell.Commands.Lists.AddListItem.ExecuteCmdlet() in c:\PnPPowerShell\src\Commands\Lists\AddListItem.cs:line 53 at PnP.PowerShell.Commands.PnPSharePointCmdlet.ProcessRecord() in c:\PnPPowerShell\src\Commands\Base\PnPSharePointCmdlet.cs:line 60 ScriptLineNumber : 1

Steps to reproduce behavior

Please find below a simplifeed sample of my script

Import-Module PnP.PowerShell -MinimumVersion 1.6.0

Connect-PnPOnline -Url $SiteURL -UseWebLogin
#OR also tried with Connect-PnPOnline -Url https://[yourtenant].sharepoint.com -Credentials (Get-Credential) 

$list = Get-PnPList -Identity Lists/MyList
$batch = New-PnPBatch
Add-PnPListItem -List $list -ContentType "Project"  -Values @{ "EEA_AFO" = '5ca0d458-d25e-4108-b311-9752dcd0db55'; } -Batch $batch
Invoke-PnPBatch -Batch $batch

I've also tried with the path of the term :/

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

ModuleType Version PreRelease Name PSEdition ExportedCommands


Manifest 1.6.0 PnP.PowerShell Core,Desk {Add-PnPClientSidePage, Add-PnPClientSidePageSection, Add-PnPClientSideText, Add-PnPClientSideWebPart…} Manifest 1.5.0 PnP.PowerShell Core,Desk {Add-PnPClientSidePage, Add-PnPClientSidePageSection, Add-PnPClientSideText, Add-PnPClientSideWebPart…} Manifest 1.3.0 PnP.PowerShell Core,Desk {Add-PnPClientSidePage, Add-PnPClientSidePageSection, Add-PnPClientSideText, Add-PnPClientSideWebPart…}

Which operating system/environment are you running PnP PowerShell on?

  • [X] Windows
  • [ ] Linux
  • [ ] MacOS
  • [ ] Azure Cloud Shell
  • [ ] Azure Functions
  • [ ] Other : please specify

Thanks for your help

lfreyss avatar Jul 19 '21 09:07 lfreyss

Hello,

I've detected that we have the same issue for the datetime field. Work well without batch parmeter and failed with same error with the batch parameter.

Also, I've removed all my PnP.PowerShell module and installed the latest nightly version, no effect :/

lfreyss avatar Jul 21 '21 15:07 lfreyss

Confirmed, we have the same issue happening with nightly build 1.6.44.

kloosterj avatar Jul 22 '21 10:07 kloosterj

@lfreyss - Can you update to the latest release and try again please. Thanks.

veronicageek avatar Sep 03 '21 16:09 veronicageek

@veronicageek The issue still persists in 1.7.45 with datetime fields. The same command works fine without -Batch

$batch = New-PnPBatch
Add-PnPListItem -List $listName -Values @{"LastUpdated"="2020-06-13T07:58:42.0000000+02:00"} -Batch $batch
Invoke-PnPBatch -Batch $batch
#Invoke-PnPBatch : Object reference not set to an instance of an object.
 Get-PnPException
#Message          : Object reference not set to an instance of an object.
#Stacktrace       :    at PnP.PowerShell.Commands.PnPSharePointCmdlet.ProcessRecord()
#                      at System.Management.Automation.CommandProcessor.ProcessRecord()
#ScriptLineNumber : 1

Swampen avatar Sep 09 '21 14:09 Swampen

Might be worth trying to explicitly typecast the value to DateTime, which resolved a similar issue for me. So: Add-PnPListItem -List $listName -Values @{"LastUpdated"=[datetime]"2020-06-13T07:58:42.0000000+02:00"} -Batch $batch

kloosterj avatar Sep 10 '21 05:09 kloosterj

@kloosterj Thanks, that worked wonderfully.

Swampen avatar Sep 10 '21 06:09 Swampen

Had the same problem Add-PnPListItem batch problem fixed by an explicit typecast of a value to DateTime.

Invoke-PnPBatch : Object reference not set to an instance of an object. At .......ps1:250 char:5

  • Invoke-PnPBatch -Batch $batch2
    
  • ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    
    • CategoryInfo : NotSpecified: (:) [Invoke-PnPBatch], NullReferenceException
    • FullyQualifiedErrorId : System.NullReferenceException,PnP.PowerShell.Commands.Base.InvokeBatch

HudsonCFoxtel avatar Sep 15 '21 03:09 HudsonCFoxtel

Fixed this issue. Should be available in tomorrow’s nightly.

Thanks for reporting 😊

gautamdsheth avatar Oct 31 '21 00:10 gautamdsheth