Bulk Delete with Dynamics365

No matter what project you are on, you are at one point or another going to need to delete data.

Your environment will become polluted and you going through each entity or manually queuing up your own delete jobs will not be worth your time.

To bulk delete your entire environment you can make use of the Bulk Delete API with the following lines of code.

QueryExpression bulkquery = new QueryExpression();
bulkquery.EntityName = entity.LogicalName;
bulkquery.Distinct = false;

BulkDeleteRequest request = new BulkDeleteRequest
{
JobName = String.Format("System Purge Requested for Entity [{0}] - All Records", bulkquery.EntityName),
QuerySet = new[] { bulkquery },
StartDateTime = DateTime.Now.ToUniversalTime(),
ToRecipients = new[] { currentUserId },
CCRecipients = new Guid[] { },
SendEmailNotification = false,
RecurrencePattern = String.Empty
};

ExecuteMultipleResponse response = new ExecuteMultipleResponse();
response = (ExecuteMultipleResponse)_svc.CrmService.Execute(multipleRequest);

Of critical importance is the

Read More


Dynamics SDK Fault Errors

Recently I was running some code against the Dynamics SDK that was taking a significant amount of time to run (transferring of data).  In my naivety, I had thought that by constantly doing “something” on that live connection my token would be refreshed.

Not the case.

It seems tokens from the Dynamics SDK are set at the time of connection and kept for the duration of the connection and not updated until you do so again.

To avoid having my connection cut during this migration (which was bad), I added some logic to check when the connection had last logged in, do a quick comparison of X minutes (in my case I chose 90 minutes but it could be more) and triggered a reconnect/refresh of my token.

The code is nothing spectacular, but understanding

Read More


File Source Encoding

I’ve been doing some migration from CSV files over the last few months that resulted in some interesting exercises in the cleansing of data before it gets to Dynamics.

For all of this work, the code was written using C# and the Dynamics SDK.

Encoding

I ran into a number of encoding problems in transferring data from the files into Dynamics. Initially, I thought Dynamics could not handle the character set but on closer inspection, it was the code that wasn’t loading it properly.  I tried a number of different Encoding formats but the one that addressed all scenarios as using the Encoding.Default and let the system decide which to use and when.

Therefore, when loading the data, my initial delimited looked as follows;
var data = File.ReadAllLines(file, Encoding.Default).Select(a => a.Split('\n').ToList());

Delimiters

Since all the data

Read More


Unified Service Desk Customization Files

I’ve been doing some custom hosted control work for the Unified Service Desk lately and wanted to implement the ability to have my controls download automatically on any new deployment without having to copy them over.

The benefits of this approach is that you are not putting your files into your main install directory (and potentially corrupting your USD install) but rather deploying them to your App/Local Data folder where they will be automatically downloaded.

Neil Parkhurst does a great job on the walkthrough there – https://neilparkhurst.com/2017/08/01/usd-customization-files/ – so I’m not going to take away from that.

What I do want to highlight are some other issues I ran into when trying to get things to deploy;

  1. If your zip file is more than 5MB you are going to need to increase your file upload

    Read More


What a Concept?

If you’ve been reading my old blog ForgottenCoder for a while, you know the focus has been primarily on Dynamics and anything that breaks off of it.  Forgotten Coder was a fun experiment but I wanted to keep the focus going on Dynamics and what I learn through it and make that content a little more organized.

Hence, 365Concepts.com.

(that’s it, no other big reveal, thanks for reading, contact if you have questions).

Read More