How to Create Test Data with Known GUIDs in Microsoft Dynamics 365

When developing for Dynamics 365, there are times when it can be very handy to have test data with specified GUIDs, particularly when troubleshooting code that finds and returns or otherwise manipulates the GUIDs of entities, or entity references.

In such situations, it may make sense to create a range of test data with known GUIDs in Dynamics 365. This can be accomplished quite easily, using either a console application, or JavaScript.

Entities can be created with a specified GUID by specifying the GUID as part of the attribute set in creation, so it’s simply a matter of selecting an easily identifiable GUID for use. In the following examples, I’ll give a snippet of sample code demonstrating how to create an Account record with the Web API and using the IOrganizationService sdk, which is possible to obtain via a console app.

Creating via WebAPI

This can either be run from the console or as part of a web app. If you’re creating records, I’d suggest running it from the console.

image thumb How to Create Test Data with Known GUIDs in Microsoft Dynamics 365

For the purposes of this example, I’ve hardcoded all values except for the id, but it would definitely be possible to pass in additional parameters for variables such as api version, account name, or any additional attributes you may wish to set.

Creating via Console App (C#)

For information on how to connect to Dynamics 365 via a console app, sample console apps can be found as part of the Dynamics 365 SDK.

image thumb 1 How to Create Test Data with Known GUIDs in Microsoft Dynamics 365

The record is created as usual, using the IOrganizationService obtained from the Dynamics 365 instance.

Let’s block ads! (Why?)

Magnetism Solutions Dynamics CRM Blog