microsoft / PowerPlatform-DataverseServiceClient

Code Replica for Microsoft.PowerPlatform.Dataverse.Client and supporting nuget packages.
MIT License
281 stars 51 forks source link

Create Post fails with Exception due to "An undeclared property 'regardingobjectid'" #108

Closed zaha closed 2 years ago

zaha commented 3 years ago

Hi,

I want to create a Post on the activity wall of a contact like this:

IOrganizationService service = new ServiceClient(new Uri(crmBaseUrl), clientId, clientSecret, true);

var post = new Entity("post");
post["text"] = "My test post";
post["source"] = new OptionSetValue(1); // Autopost
post["regardingobjectid"] = new EntityReference("contact", new Guid("9a6da95d-8945-e711-80ed-005056844077"));

service.Create(post);

This works fine with 0.2.1-Alpha of the library. As soon as I update to any more recent version (latest try was with 0.4.4 now), I get the following error:

Microsoft.PowerPlatform.Dataverse.Client.Utils.DataverseOperationException : An error occurred while validating input parameters: Microsoft.OData.ODataException: An undeclared property 'regardingobjectid' which only has property annotations in the payload but no property value was found in the payload. In OData, only declared navigation properties and declared named streams can be represented as properties without values. ----> Microsoft.Rest.HttpOperationException : Operation returned an invalid status code 'BadRequest'

Am I missing something here, was there a change in the library concerning this? The same approach works for me when creating a Note/annotation with objectid as well, both in 0.2.1-Alpha and 0.4.4.

image (green border is note created with 0.4.4 and red border is a post created with 0.2.1-Alpha)

I was thinking maybe the name of the field changed and the id is not needed any, so when I name the field regardingobject I get this error:

System.AggregateException : One or more errors occurred. (Entity Reference regardingobject was not found for entity post.) ----> Microsoft.PowerPlatform.Dataverse.Client.Utils.DataverseOperationException : Entity Reference regardingobject was not found for entity post.

I'm clueless what is wrong here. Am I doing something wrong or is this maybe a bug with the library? Would appreciate any input.

Kind regards Michael

JimDaly commented 3 years ago

There is an issue with the Post entity. It has never worked properly with the Web API (OData) endpoint. While the DataverseServiceClient is using Web API, it won't work until that is fixed. I have assurances it will be fixed in the next semester.

zaha commented 3 years ago

Ohh, I see. So this means up to 0.2.1-Alpha, the library was internally still using the old API for creating posts and starting with later versions it has been switched to Web API. Thank you for clarifying!

Great to hear this is going to be fixed in the near future, as this is something my organization uses on a regular basis. Can I then leave this ticket open until this is implemented so I get notified when creating Posts is possible with the Dataverse Service Client?

MattB-msft commented 3 years ago

Flagged it as a bug and will close it when we get the word the server side is fixed.

zaha commented 2 years ago

Any news on this issue? It's a bit frustrating to be stuck with 0.2.1-Alpha when version 1.0 is out now. 😁

fowl2 commented 2 years ago

Perhaps try setting UseWebApi to 'false' as a workaround?

zaha commented 2 years ago

Wasn't even aware of that setting, will give it a try. Thanks for the tip!

MattB-msft commented 2 years ago

You do need to update to the 1.X release for access to the UseWebAPI property @zaha

zaha commented 2 years ago

I updated to the latest version 1.0.9 and found that I am able to set the regardingobjectid property now without any error. So seems like the bug was fixed along the way sometime and this ticket can be closed! :)