0

We have a list item which also contains user field (single user). On our app customer is able to clear peoplepicker thus requiring this filed to be updated -> cleared. However even we have logic to do that (using value -1 for user ID), this is creating a problem on list item itself. When you later want to check it you can see this (view item):

enter image description here As you can see, it will generate some kind of "empty" user. However when you want to edit item you'll get typical "Sorry, something went wrong" SharePoint page. I also tried to compare values when gathering back the data. When you get item and field was "cleared" using normal SP edit page, response from API call is (an empty 'link' element):

enter image description here

However with this -1 value it looks like this:

enter image description here

Does anyone have experience with this and possible solution please? Or it is just another not well done functionality in SharePoint? We tried other values like 0, null, or just empty string. However error returned from server is clear, it expects Int32 value. Update is done by using PATCH method calling standard getItemByStringId(itemId).

1 Answer 1

0

After some time I figured out how to do it. Common suggestions are wrong, using -1 a value will not clear out this field neither other (non)values. However solution is there. All I needed to do was to add 'null' attribute actually. I figured this out when I noticed that this is the format SP is using when returning field values which contains nothing. So code in C# is simple:

XNamespace DNamespace = "http://schemas.microsoft.com/ado/2007/08/dataservices"; XNamespace MNamespace = "http://schemas.microsoft.com/ado/2007/08/dataservices/metadata"; XElement fieldElement = new XElement(DNamespace + propertyName, new XAttribute(MNamespace + "null", "true")); 

This will create new XML element with the name of the field (propertyName) and includes attribute m:null="true". Like this:

<d:SomeDate m:null="true" /> 

Works like charm on both person and datetime fields.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.