[BUG] - Add/Set-PnPListItem with managed metada / taxonomy field value failed on a batch request
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
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 :/
Confirmed, we have the same issue happening with nightly build 1.6.44.
@lfreyss - Can you update to the latest release and try again please. Thanks.
@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
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 Thanks, that worked wonderfully.
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
Fixed this issue. Should be available in tomorrow’s nightly.
Thanks for reporting 😊