MS Tech & Coffee

Thoughts of a .NET Developer turned into MS Dynamics architect turned into Power Platform Director turned into AI and Business Transformation Global Lead… all views are my own!

Lately, I have been playing a lot with the Dynamics 365 Web API, rather than using HTTP Request directly I decided to try David Yack’s library which so far is working great!

https://github.com/davidyack/Xrm.Tools.CRMWebAPI/tree/master/dotnet

Because I was using Azure Functions v2 I couldn’t use the Dynamics 365 Core Assemblies so I had to improvise a little bit when creating records.

Strings are of course fine, Statuses and Option sets you can use the numeric value and it will work, but what about Lookups?

If we check the SDK we can see that the request should follow this format:

https://docs.microsoft.com/en-us/dynamics365/customer-engagement/developer/webapi/create-entity-web-api

{

“name”:”Sample Account”,

“primarycontactid@odata.bind”:”/contacts(00000000-0000-0000-0000-000000000001)”

}

What about when we are using ExpandoObjects like in David’s library? Well, just cast it to a Dictionary and send that instead 🙂


dynamic account = new ExpandoObject(); //We won’t be using this one anymore.
var accountDict = (IDictionary)account;
accountDict.Add("primarycontactid@odata.bind", "contacts(54210106-dbeb-e711-a952-000d3a296acd)");
accountDict.Add("name ", “Sample Account”);

Guid createdAccount = await api.Create("accounts",accountDict);

Hope it helps!

Mario

Leave a comment

I’m Mario

Welcome to MS Tech & Coffee, a project I started more than 8 years ago as a place where I could drop things that I was encountering in my journey as .NET developer in the UK. That journey has taken me to many places and now looking back I want to use this project to share some of my personal views on technology, AI, the Microsoft ecosystem and of course.. a bit of coffee!

Let’s connect