msgraph-sdk-powershell icon indicating copy to clipboard operation
msgraph-sdk-powershell copied to clipboard

Update-MgSiteListItem with $null value not updating the field value

Open jolscr opened this issue 1 year ago • 7 comments

Describe the bug

I want to clear the value of the field "TeamArchivingDate" (Date Type) by passing $null to the parameter. If I use PnP it works, but if I user graph it doesn't work.

the issue occurs with column type "Date" but "multiline" too.

Expected behavior

The column TeamArchivingDate of my item must be empty after that.

How to reproduce

Update-MgSiteListItem -SiteId $TeamRequestsSiteId -ListId $TeamRequestsListId -ListItemId 5334 -Fields @{"TeamArchivingDate" = $null} -ErrorAction:Stop

SDK Version

2.4.0

Latest version known to work for scenario above?

No response

Known Workarounds

use PNP : Set-PnPListItem -List $TeamsRequestsListName -Identity 5334 -Values @{"TeamArchivingDate" = $null} -Connection $connection

Debug output

Click to expand log ```
</details>


### Configuration

Name                           Value
----                           -----
PSVersion                      7.2.6
PSEdition                      Core
GitCommitId                    7.2.6
OS                             Microsoft Windows 10.0.22631
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

### Other information

_No response_

jolscr avatar May 07 '24 14:05 jolscr

Hi Jolscr,

I haven't had a change to replicate this myself yet, but have seen something similar in previous issues. If you try to drop the dollar sign in front of null, does it work?

e.g. -Fields @{"TeamArchivingDate" = null}

I'm referencing: https://github.com/microsoftgraph/msgraph-sdk-powershell/issues/2609#issuecomment-1957967636

SeniorConsulting avatar May 07 '24 20:05 SeniorConsulting

Thank you for your message but doesn't work. image

jolscr avatar May 08 '24 05:05 jolscr

@jolscr kindly share the debug information provided by adding the -Debug parameter

Ndiritu avatar May 08 '24 08:05 Ndiritu

I update SDK to 2.18, but same issue. The issue is related to the body fields, because we can see that the field "TeamDeletionDate" is removed from the request:

image

image

jolscr avatar May 08 '24 09:05 jolscr

@jolscr thank you for sharing the debug info. This is indeed a bug. While investigate this issue kindly try using Invoke-MgGraphRequest command. In your case it will be something like below

fields = @{"TeamDeletionDate" = $null, "TeamLogs" = ""}
Invoke-MgGraphRequest -Method PATCH -Uri "https://graph.microsoft.com/v1.0/sites/<Your siteId>/lists/<Your listId>/items/<Your listItemId>" -Body $fields

timayabi2020 avatar May 09 '24 01:05 timayabi2020

Thank you @timayabi2020. This is a workaround, but I hope it will be fixed in the future.

Here's the working code :

$fields = @{fields = @{
		"TeamLogs"="";
		"TeamDeletionDate"=$null
		}}

Invoke-MgGraphRequest -uri "https://graph.microsoft.com/v1.0/sites/$siteid/lists/$listid/items/$itemid" -method PATCH -body $fields

jolscr avatar May 14 '24 12:05 jolscr

I have observed this same problem, in my case it is with Number type columns, which do not require a value. I also can work around this by using anything other than Graph PowerShell SDK modules, such as the workaround @jolscr supplied. But I want to use Update-MgSiteListItem since it's official and I'm working on scripts for real life customers.

You can see below that it doesn't even generate an error when we supply $null, it just ignores it and pretends everything is happy: image

... and if we check the version history on the list item, we can see an empty update is coming in: image

JeremyTBradshaw avatar Jul 17 '24 12:07 JeremyTBradshaw