When we’re creating Dynamics 365 solutions, we often need to create “reference” entities which we use with lookup fields to give us more flexibility than basic option set fields. For example, having a lookup for Country on accounts. When populating the lookup values for these entities, the system assigns a random GUID to each record.
The problem comes when we’re working with Development environments, Production environments, and UAT environments for the same solution, the reference data created in each environment is going to have different GUID’s, which means even if we create the exact same values (e.g. with the same “Name”), as soon as we need to reference them by GUID, the values are going to be different.
This means we’re going to face problems with any views, business rules, workflows, or anything else that needs to do filtering by a specific record. This is because if we create a view in the development environment which filters by one of those lookup values, it’s going to look for that same record by GUID when we deploy the solution to UAT or Prod.
I’ve discussed workarounds for this in the past, which includes referencing the lookup values by name, rather than by GUID.
The only way to specify your own GUID when creating a record is to create the record using the SDK. So with this in mind, I’ve created a user-friendly bookmarklet which uses the Web API to create a record of our choice, using a GUID of our choice. This means we can easily create reference data in our Dev, UAT, and Prod instances using the same GUID’s, so we don’t have to worry about facing issues when we deploy our solution.
Simply copy the following code into a browser bookmarklet, then launch it from any Dynamics 365 screen. You’ll be prompted for the entity schema name, and then the GUID you want to use. Once confirmed, the record will be created using the specified GUID, and the form will then be opened for you to complete the rest of the fields. At this point, the record has already been created, and the GUID has already been set. And that’s it! No more worrying about lookup-related errors after deploying.
You can also check out a bunch of other cool Dynamics 365 bookmarklets on this GitHub project.