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

The attribute with AttributeId = ‘guid’ was not found in the MetadataCache

I encountered this error when trying to export the solution from Dev environment. There was little information in the exception or the log file, but I could guess that something had been deleted and it didn’t update the MetadataCache (or the solution) somehow.

After googling, I found the solution is to delete the attribute/component from the CRM solution.

private static void RemoveComponentFromSolution(IOrganizationService service, Guid componentId, int componentType, string solutionName)
{
	RemoveSolutionComponentRequest removeRequest = new RemoveSolutionComponentRequest()
	{
		// this is the Guid you have found within your Dynamics 365 trace files
		ComponentId = componentId,
		ComponentType = componentType,
		// This is the unique name, not the display name of the solution you are trying to export
		SolutionUniqueName = solutionName
	};

	var response = service.Execute(removeRequest);
}

The component type can be retrieved using FetchXML

<fetch top="50" >
  <entity name="solutioncomponent" >
    <all-attributes/>
    <filter type="and" >
      <condition attribute="objectid" operator="eq" value="component guid here" />
    </filter>
  </entity>
</fetch>

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”

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.

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”

Convert Word to PDF in Dynamics 365 CE Online with Flow (Part 3)

Today I will show you how we can put the Flow we created in the previous part into action. Continue reading “Convert Word to PDF in Dynamics 365 CE Online with Flow (Part 3)”

Convert Word to PDF in Dynamics 365 CE Online with Flow (Part 2)

I discussed about advantages and disadvantages of different approaches in part 1. I’ll cover how we can achieve our goal with Flow in this part. Continue reading “Convert Word to PDF in Dynamics 365 CE Online with Flow (Part 2)”