Retrieve Record using Alternate Keys

Instead of retrieve a single record using

Entity IOrganizationService.Retrieve(string entityName, Guid id, ColumnSet columnSet);

You can easily retrieve the record using its alternate keys if you don’t have the id in advance:

var keys = new KeyAttributeCollection
{
	{ "new_parent", parentRef.Id },
	{ "new_code", "code01" }
};

var request = new RetrieveRequest
{
	ColumnSet = new ColumnSet("field_logical_name"),
	Target = new EntityReference("entity_logical_name", keys)
};

try
{
	var response = (RetrieveResponse)service.Execute(request);
	if (response.Entity != null)
	{
		service.Delete(response.Entity.LogicalName, response.Entity.Id);
	}
}
catch (Exception)
{	
}

Note that if there is no record matched the keys, an exception will be thrown, you’ll need to handle the exception in that case.

Advertisements

Sync Office 365 User Photos to CRM Users with Flow

Background

I got a requirement that the client needs user profile photos in Office 365 to be synced to CRM Users. It is Dynamics 365 CE Online, and users don’t change profile photo often. There is no OOB way to achieve it so I need to develop custom synchronization.

Continue reading “Sync Office 365 User Photos to CRM Users with Flow”

“Record is unavailable” error when publishing solution

Problem

When publishing unmanaged solution, this error shows up

Record Is Unavailable

The requested record was not found or you do not have sufficient permissions to view it.

Although you have system admin role. Even worse, the download error log button is disabled and you can’t find out which component causing the error.

Solution

Clearly that there is something in the solution which you can see, but the system can’t.

If you try to pulish components one by one, there will be no error. But publishing all won’t work.

It will be quicker if you can narrow down what are added recently that may cause the error. Then you can use a different tool to publish the solution, either writing your own tool or use a plugin in XrmToolbox called “Manage Solution”, to catch the exception and see what the root cause is.

In my case it was a web resource, I deleted it and publishing all worked like a charm. Note that removing it from the solution doesn’t help.

Capture.PNG

Cheers!

Introducing Deduplicator for XrmToolBox

Have you encountered these limitations when working with Duplicate Detection functionalities in Dynamics 365?

You can include only 450 characters in the matchcode. Either change or delete rule conditions to reduce the number of characters included, and then try again.

Bulk Detect Duplicate Limit Exceeded. The Bulk Duplicate Detection job cannot detect more than 5000 duplicates. Please review your duplicate rules or resolve existing duplicates and rerun the job

Although the OOB duplicate detection functionalities are useful in some cases, I often find myself wasting hours to workaround those limitations when dealing with large amount of data. So I decided to build a solution which allows me to quickly query for duplicates and see how many records duplicated.

Introducing Deduplicator

dd1.png

Deduplicator is a plugin for XrmToolBox. You can download the plugin in XrmToolBox Plugin Store.

What Deduplicator can do

In the first release, it has below features:

  • Allows matching multiple fields with no length limitation.
  • Allows searching more than 5000 records.
  • Allows selecting fields for results view.
  • Shows total of duplicated records

Deduplicator is open source

Empowerment of individuals is a key part of what makes open source work, since in the end, innovations tend to come from small groups, not from large, structured efforts. – Tim O’Reilly

You can find the source code of the plugin in Github at:

https://github.com/khoait/DynCrmExp.Deduplicator

Please rate and share the plugin if you think it helpful, also don’t hesitate to leave any comment here or in the GitHub to make it better or if you find any bugs.

Field Restriction in Alternate Keys

Alternate keys is a useful functionality introduced from CRM 2016. It allows you specify one or more fields to be an alternate key and use it to identify a record instead of using GUID. This is extremely helpful when you work with data migration and/or data integration between systems. More about Altenate Keys here.

Only attributes of the following types can be included in alternate key definitions: Decimal, Whole Number, Single line of text.

However, there are some restrictions in what field can be selected as alternate keys which the document doesn’t mention. Below is the non-exhausted list of them, I’ll update this if I find more:

  • Secured fields. A field with “Field Security” enabled doesn’t show up in the list when you creating alternate key.
  • “fullname” in “contact” entity
  • “domainname” in “systemuser” entity

So be aware when you work with alternate keys. Hope it helps!

 

When to trigger plugin or workflow on Survey Response Voice of Customer

Voice of Customer (VoC) is a excellent tool for survey editor right in CRM, though it still lacks some nice to have functionalities. I’m not going to discuss about VoC in this post.

Survey Response is a entity collecting all Answers for Questions in the Survey. When user submits the survey, Survey Response and Answers will be created in CRM from Azure. The Survey Reponse will be created first and then related Answers will be created and look up to the Survey Response. This happens asynchronously.

So if we want to trigger a plugin or a workflow on Survey Reponse, we want to make sure the Survey Reponse has been created and all related Answers have come through. We shouldn’t trigger it on creation of the Survey Response as not all the Answers created in CRM; we shouldn’t trigger on creation of Answers either as Answers are created unorderly, the last answer may be created first. Instead, we should use an OOTB field called “msdyn_processingcompletetrigger”, it will be updated to Yes if the Survey Reponse and all Answers are created.

surveyresponsetrigger.png

Cheers!

Can’t set record Status Reason to default value in CRM Worklfow with Status Transition Rules Enabled

I encountered a weird case when trying to set record status reason to default value on creation of the record in CRM Workflow with Status Transition Rules enabled in the entity configuration. I’ll replicate the case and implement a workaround in my trial CRM Online instance. Continue reading “Can’t set record Status Reason to default value in CRM Worklfow with Status Transition Rules Enabled”