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.
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.
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.
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.
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.
The record is created as usual, using the IOrganizationService obtained from the Dynamics 365 instance.