Open Chris-Leeworthy opened 7 years ago
I'm having this exact same issue .... Please advise
Something seems to have changed in the past few days in SharePoint online, it first occurred yesterday for us. The problem seems to be related to SystemUpdate, which no longer work when adding an item in SharePoint Online, maybe an update to https://github.com/SharePoint/PnP-PowerShell/blob/fb01372c1d1b2146bdbd290b6acefcbff0882713/Commands/Lists/AddListItem.cs#L176 can resolve it.
Same issue for me!
I think you need to use a list object rather than a listname. Use get-pnplist to get the list.
It still crashes with the same error regardless of whether I give the list name or I pass in a list object obtained by Get-PnPList.
Either way it crashes with "Operation is not valid due to the current state of the object"
I have the same issue with both Feb and March release of PnP PowerShell for SharePoint Online.
edit: Re-installed January release and it works again.
@mrik23 Interesting to know, thank you.
Do you know if there is some way for me to get hold of the older release?
Ah! Never mind, I found it, (note to self, look first then ask!)
The January release of the PnP cmdlets works for me too.
I guess something changed between the January and February versions?
I'm seeing the same issue on the March release. I've noticed that the command works if the ContentType parameter is specified:
Works:
Add-PnPListItem -List $list -Values $listItemInfo -ContentType "Item"
Doesn't work:
Add-PnPListItem -List $list -Values $listItemInfo
(Edit: this seems to work with a full admin but NOT as user with Contribute permission on list. Haven't probed, just abandoned this method until resolved in favor of AddItem method on List object.)
Had same issue whilst following this blog, Channel9 demo https://channel9.msdn.com/Blogs/MVP-Azure/Work-with-SharePoint-Online-lists-with-PNP-PowerShell
Had the same issue, here is my workaround:
#this one fails:
$onenoteitem = @{
Title = "Notebook"
BackgroundImageLocation = "$onenote, $onenote"
LinkLocation = "$($targetSiteUri.LocalPath)/_layouts/15/WopiFrame.aspx?sourcedoc=$($targetSiteUri.AbsoluteUri)/SiteAssets/Team Site Notebook&action=editnew, $($targetSiteUri.LocalPath)/_layouts/15/WopiFrame.aspx?sourcedoc=$($targetSiteUri.AbsoluteUri)/SiteAssets/Team Site Notebook&action=editnew"
LaunchBehavior = "In page navigation"
TileOrder = "0"
}
Add-PnPListItem -List $promotedlinkslist -Values $onenoteitem
#this does the same, but works
$list = Get-PnPList $promotedlinkslist
$itemcreateinfo = New-Object Microsoft.SharePoint.Client.ListItemCreationInformation
$listitem = $list.AddItem($itemcreateinfo)
$listitem["Title"] = "Notebook"
$listitem["BackgroundImageLocation"] = "$onenote, $onenote"
$listitem["LinkLocation"] = "$($targetSiteUri.LocalPath)/_layouts/15/WopiFrame.aspx?sourcedoc=$($targetSiteUri.AbsoluteUri)/SiteAssets/Team Site Notebook&action=editnew, $($targetSiteUri.LocalPath)/_layouts/15/WopiFrame.aspx?sourcedoc=$($targetSiteUri.AbsoluteUri)/SiteAssets/Team Site Notebook&action=editnew"
$listitem["LaunchBehavior"] = "In page navigation"
$listitem["TileOrder"] = "0"
$listitem.Update()
Execute-PnPQuery
Thanks @NoahStahl - that was the clincher ! I guess it's trying to create a new item, but doesn't know what content type. -ContentType Item
@NoahStahl thanks indeed adding the content type does the trick. Not sure that's a bug or a feature :) Would be cool if the documentation get an update.
Same issue here with SharePoint Online and the April release (2.14.1704.0) even with the -ContentType parameter. The following code did the trick ("Add" then "Set" the item):
$Item = Add-PnPListItem -List $List
Set-PnPListItem -Identity $Item.Id -List $List -Values $Values
looks similar with this: https://github.com/SharePoint/PnP-PowerShell/issues/799
I have the same problem with the May Update for SharePoint OnLine Neither the solution FranckyC gave, nor the workaround kmosti showed above works.
Also after reverting back to January, I still get Add-PNPListItem : List data validation Failed, and cannot proceed with the record update.
Interesting, for me with May 2017 release, FranckyC's tip of first adding empty item and only setting values later works in SPO.
$newItem = Add-PnPListItem -List $l
Set-PnPListItem -List $l -Identity $newItem -Values @{"Title" = "Title goes here"; "OtherField" = "Other field value goes here"}
Tested with the July 2017 Intermediate release, which was failing in SPO
Adding a valid -ContentType parameter also worked for me.
Can I add my name to the long list of people affected by this issue.
Tested with the July 2017 Intermediate release.
Adding a valid -ContentType parameter also worked for me.
Found the issue which is causing this problem. When using the PnP commandlet
Add-PnPListItem -List "ListName" -Values @{"Title" = "Some title"}
it is failing while it tries to set the content type to '0x01' and the default custom list contains 2 content types which are starting with '0x01' namely Item and Folder. When specifying the complete Content Type this is working correctly.
Strange thing is that when using
Add-PnPListItem -List "ListName" -Verbose
it is working while it sends the correct Content Type, in my case '0x010096B52006876EDE439EE7782F47A46F11'
Below worked for me. Add-PnPListItem -List "Type of License" -ContentType "Item" -Values @{"Title" = "Cleaning Contract"}
Can confirm that the ContentType argument helps resolve the issue.
Using Get-PnPContentType, i found that the ContentType was translated to my language (norwegian), so I had to do this:
Add-PnPListItem -List "somelist" -ContentType "Element" -Values @{"Ti.......
Element is translated from Item. Is this a bug, I wonder.
Me too. I need translate ContentType to "Elemento" to work it with italian Language!
adding -ContentType worked for me, i had to put -ContentType "Element", and not "Item".
Just come across this issue, still present on SharePointPnPPowerShellOnline 2.18.1709.1 Adding -ContentType fixed issue
Adding content type is a workaround. You can get the default list content type like this:
$defaultContentType = (Get-PnPContentType -List "myListName")[0] # First ct is always a default one $listItem = Add-PnPListItem -List "myListName" -ContentType $defaultContentType -Values $listItemMetadata
Reporting an Issue or Missing Feature
Issue
Expected behaviour
Working with a pre-existing list in a site collection with just the default Title field defined.
Using the cmdlet with the -Values parameter should create a list item populated with the specified values.
Actual behavior
An error occurs (see output below)
Steps to reproduce behaviour
Create a custom list with just the default fields (used SharePoint web interface rather than scripting). Then run the following script...
Which version of the PnP-PowerShell Cmdlets are you using?
What is the version of the Cmdlet module you are running?
(you can retrieve this by executing
Get-Module -Name *pnppowershell* -ListAvailable
) Version 2.12.1702.0How did you install the PnP-PowerShell Cmdlets?