-
Reporting an Issue or Missing FeatureConnected to Sharepoint and other PnP commands work normally. Add-PnPListItemComment -List 'Demo List' -Identity 9 -Text "Hello world" Expected behaviorPost comment to Modern SharePoint List Item. Actual behaviorThe comment is posted to the SharePoint list and terminates with an error message of: When this command is in a loop, it kills the script and does not honor any sort of error handling to bypass the termination to override it, too. Steps to reproduce behaviorPlease include complete script or code samples in-line or linked from gists $connection = Connect-PnPOnline -Url "https://yourtenant.sharepoint.com/sites/DemoSite" -ClientId -Tenant yourtenant.onmicrosoft.com -CertificateBase64Encoded $yourcert #throws an error response and posts the message to the list item. #This command will terminate the script / loop in its tracks instead of silently continuing What is the version of the Cmdlet module you are running?2.4.0 Which operating system/environment are you running PnP PowerShell on?
PowerShell Version7.4.1 |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 4 replies
-
@gautamdsheth Why was this "bug" converted to a discussion? I am working on a workaround via the Graph api for my personal code however I'm not really sure how it would help this project due to that it's in C# and my code is in PowerShell. :-) |
Beta Was this translation helpful? Give feedback.
-
@gautamdsheth Code away! :-D My workaround to the situation is to leverage Power Automate / Logic App and target the API directly. I successfully reproduced the issue by using this content type: The issue was resolved after using this content type: ::Working:: Applying the same knowledge learned from the above to the PnP module and using "Invoke-PnPSPRestMethod" the following works: Function Add-PnPListItemComments {
Param (
$List,
$Identity,
$Text
)
$metadata = @{
"type" = "Microsoft.SharePoint.Comments.comment"
}
$Content = @{
"__metadata" = $metadata
"text" = $Text
}
$ContentType = "application/json;odata=verbose"
Invoke-PnPSPRestMethod -Method Post -Url "/_api/web/lists/GetByTitle('$List')/items($Identity)/Comments()" -Content $Content -ContentType $ContentType
}
Add-PnPListItemComments -List 'Demo List' -Identity '9' -Text 'Hello World' |
Beta Was this translation helpful? Give feedback.
@gautamdsheth Code away! :-D
My workaround to the situation is to leverage Power Automate / Logic App and target the API directly.
I successfully reproduced the issue by using this content type:
"content-type": "application/json;charset=UTF-8"
The issue was resolved after using this content type:
"content-type": "application/json;odata=verbose"
::Working::
params:
{
"dataset": "https://yourtenant.sharepoint.com/sites/DemoSite",
"parameters/method": "POST",
"parameters/uri": "_api/web/lists/GetByTitle('Demo List')/items(9)/Comments",
"parameters/headers": {
"accept": "application/json;odata=verbose",
"content-type": "application/json;odata=verbose"
},
"parameters/body": "{\n "__metadata": …