Making CRM record IDs searchable

Sorry. It’s not possible.

To display the record ID of an entity on a form, in a view or in advanced find, we need to copy the value to a text attribute.

Simple enough: create a new attribute (named new_recordid or whatever you prefer) and register a plugin on the create message of your relevant entity that copies the ID. Make sure you register it post create, or your record wont have an ID yet.

Here is the plugin code. I use CRM developer toolkit so the plugin is in that style.


using System;
using Microsoft.Xrm.Sdk;

namespace Plugins
{
    public class CopyRecordId: Plugin
    {
        public CopyRecordId()
            : base(typeof(CopyRecordId))
        {
            RegisteredEvents.Add(new Tuple<int, string, string, Action<LocalPluginContext>>(40, "Create", "account", ExecuteCopyRecordId));
        }

        protected void ExecuteCopyRecordId(LocalPluginContext localContext)
        {
            if (localContext.PluginExecutionContext.Depth > 1)
                return;

            Entity entity = new Entity(localContext.PluginExecutionContext.PrimaryEntityName);
            entity.Id = localContext.PluginExecutionContext.PrimaryEntityId;
            entity.Attributes.Add("new_recordid", localContext.PluginExecutionContext.PrimaryEntityId.ToString().Trim('{', '}'));

            localContext.OrganizationService.Update(entity);

        }
    }
}