Posts in Category: dynamics 365

Dynamics SDK Paging Records

I never thought I’d have a case when I’d need to work with over 5,000 records from the Dynamics SDK.

The scenario here is that I was trying to reproduce some production issues and validate out some code changes with a higher threshold of objects.  However, as I started testing, I noticed I wasn’t bringing back everything and had hit the that magical 5,000 limit.

Without wanting to change it, I modified by query to support the retrieval of 5,000+ items that would return to my service to be worked on.

bool KeepSearching = true;
 EntityCollection results = null;
 Dictionary <Guid, Entity> Accessors = new Dictionary<Guid, Entity>();

QueryExpression query = new QueryExpression();
 query.EntityName = "contact";
 query.Criteria.AddCondition(new ConditionExpression("contactid", ConditionOperator.Equal, ContactId));
 query.ColumnSet = new ColumnSet(new string[] { "contactid", "fullname"});
 query.PageInfo = new PagingInfo();
  query.PageInfo.PageNumber =															

Read More


ASP.NET Web API Usage with Dynamics Web Api

I’ve blogged about connection setup with the Dynamics Web API over the last little while – Getting it Setup and how to use with the USD.

One critical piece that I forgot (or rather overlooked) that needs to be mentioned is what is called the “Headless” connection.  This is a connection to your Dynamics tenant that does not use a Username or Password combination and does not prompt the user to enter in their credentials when accessing.

In my previous examples, my Application type was “native”, however, for this to work in a headless modality in a web api world, this needs to be configured as Web app / API.  If not configured this way, you will always be prompted for access to your Dynamics

Read More


Identifying when a Dynamics Plugin Fires

I recently had a problem where we had multiple events tied to a single plugin (not the perfect architecture, but one I had to work with) on the disassociation of a record from a Many-2-Many grid.

pluginevents.png

The problem with the above implementation is that for each Disassociation even we were registered for both the Pre and Post events (whereas one plugin required both, but another only required the Post event).

To detect which even the plugin was handling I was able to key off the following Input Parameter to what event was firing.

localContext.PluginExecutionContext.InputParameters.Contains("parentExecutionId")

If the “parentExecutionId” variable existed, I was in the Pre-Step and if it did

Read More


Saving data with the Dynamics Web Api

In my previous posts on using the Dynamics Web Api, I invested a significant amount of time in figuring out the connection protocols, querying and accessing data from the results (not being an Azure, Active Directory or JSON expert).

However, when it came to saving data, the hard work was over and I was able to do with relative ease.

To save data via the Dynamics Web API, the interface is quite similar to how you would access your controls via LateBinding except that instead of the Entity object you are consuming a JObject.

JObject phoneCall = new JObject();
 phoneCall["subject"] = "Here comes my call";
 phoneCall["phonenumber"] = "888-999-7777";
 phoneCall["scheduledend"] = DateTime.Now;
 phoneCall["description"] = "Who called me.";
//The Direction Code is always an incoming call.
 phoneCall["directioncode"] = false;

string recordId = string.Empty;
 try
 {
 HttpClient httpClient =															

Read More


Retrieving Data with the Dynamics Web API

So after I worked that whole plural entity name thing on getting data from Dynamics, I now had my data coming back to me in a wonderful Json format.  When interacting with data from the Web API you query for information via the rest interface of your URL. (more on MSDN).

As an example, if I wanted to retrieve some information on a custom entity I could do it using this query syntax.

HttpResponseMessage response = await httpClient.GetAsync(dyanmicsTenant + "/api/data/v8.1/enc_medias?$select=dat_name,_dat_customer_value,dat_dataid&$filter=dat_name eq '" + SearchParameter + "'");

Which would return a Json package in the format of

{
"@odata.context":"https://myCrmTenant.crm.dynamics.com/api/data/v8.1/$metadata#datas(dat_dataid,dat_name)","value":[
{
"@odata.etag":"W/\"874140\"","dat_dataid":"fd95bfa1-ddb8-e711-8114-c4346bdcf161","_dat_customer_value":"{00665E23-779E-4C8C-A5D4-36213C41EA27}","dat_name":"0000000006"
}
]
}

A few things…

What is _dat_customer_value?

In my query, I wanted to get the lookup for a customerid, the field itself is called data_customerid, however, when accessing lookups you must prepend “_” to the field and append “_value” to the

Read More