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

Can't delete single-value extended property for calendar

Open schoesa opened this issue 4 years ago • 3 comments

Describe the bug Can't delete single-value extended property for calendar.

To Reproduce I have created a single-value extended property for my default calendar.

Code to set value for calendar:

var userConfig = JsonConvert.SerializeObject(data);
var propertyId = $"{MAPIPROPERTYTYPE} {{{NAMESPACEGUID}}} Name {_configuration[KEYNAMEEXCHANGECONFIGPROPERTY]}";

var customProperty = new SingleValueLegacyExtendedProperty
{
	Id = propertyId,
	Value = userConfig
};

var calendar = await _graphClient.Users[data.User.UserId].Calendar.Request().Expand($"singleValueExtendedProperties($filter=id eq '{propertyId}')").GetAsync();

var updateCalendar = new Calendar
{
	Id = calendar.Id
};

var extendedValueCollection = new CalendarSingleValueExtendedPropertiesCollectionPage {customProperty};
updateCalendar.SingleValueExtendedProperties = extendedValueCollection;

await _graphClient.Users[data.User.UserId].Calendar.Request().UpdateAsync(updateCalendar);

Code to remove value:

var propertyId = $"{MAPIPROPERTYTYPE} {{{NAMESPACEGUID}}} Name {_configuration[KEYNAMEEXCHANGECONFIGPROPERTY]}";
var calendar = await _graphClient.Users[userId].Calendar.Request().Expand($"singleValueExtendedProperties($filter=id eq '{propertyId}')").GetAsync();
                
var updateCalendar = new Calendar
{
	Id = calendar.Id
};

updateCalendar.SingleValueExtendedProperties = null;

await _graphClient.Users[userId].Calendar.Request().UpdateAsync(updateCalendar);

Code to read value:

 var value = string.Empty;
 var propertyId = $"{MAPIPROPERTYTYPE} {{{NAMESPACEGUID}}} Name {_configuration[KEYNAMEEXCHANGECONFIGPROPERTY]}";

var calendar = await _graphClient.Users[userId].Calendar.Request().Expand($"singleValueExtendedProperties($filter=id eq '{propertyId}')").GetAsync();

var properties = calendar.SingleValueExtendedProperties;

if (properties == null)
{
	return value;
}

var customProperty = properties.CurrentPage.First();

value = customProperty.Value;

if (string.IsNullOrEmpty(value))
{
	_log.LogInformation($"No config for user {userId} found");
}

_log.LogInformation($"Config for user {userId} found: {userId}");

return value;

Expected behavior The value for the extended calendar property should be null. Instead I get the following JSON: image

Desktop (please complete the following information):

schoesa avatar Jun 23 '20 11:06 schoesa

When you call await _graphClient.Users[userId].Calendar.Request().UpdateAsync(updateCalendar);, what are you seeing for the request and response? Are you able to make the update using Graph Explorer.

A quick look at the docs shows me little about this scenario.

https://docs.microsoft.com/en-us/graph/api/resources/singlevaluelegacyextendedproperty?view=graph-rest-beta

MIchaelMainer avatar Jun 25 '20 20:06 MIchaelMainer

You may get better answer coverage on StackOverflow for this question. I suggest that you x-post and add a link here.

MIchaelMainer avatar Jun 25 '20 20:06 MIchaelMainer

@MIchaelMainer thx for your quick response. In the meantime I found a solution to delete the single-value extended property for the calendar. Nevertheless I am convinced that this is a bug.

Code to delete property:

var propertyId = $"{MAPIPROPERTYTYPE} {{{NAMESPACEGUID}}} Name {_configuration[KEYNAMEEXCHANGECONFIGPROPERTY]}";

var customProperty = new SingleValueLegacyExtendedProperty
{
	Id = propertyId,
	Value = null    // set null to delete single-value extended property
};

var calendar = await _graphClient.Users[userId].Calendar.Request().Expand($"singleValueExtendedProperties($filter=id eq '{propertyId}')").GetAsync();

var updateCalendar = new Calendar
{
	Id = calendar.Id
};

var extendedValueCollection = new CalendarSingleValueExtendedPropertiesCollectionPage {customProperty};
updateCalendar.SingleValueExtendedProperties = extendedValueCollection;

await _graphClient.Users[userId].Calendar.Request().UpdateAsync(updateCalendar);;

schoesa avatar Jun 26 '20 08:06 schoesa

closing older issues. Please reopen if occurs on V5 or greater.

ddyett avatar Jun 28 '23 01:06 ddyett