Monday, December 8, 2014

Get list of Entities in CRM query by Display Name (CRM bulk update)

Hello World,


MetadataSchema.Entity does not have the Display Name of the Entity in it. To get Display Name of a Entity we have to use MetadataSchema.LocalizedLabel
In the bellow query I get the all Entities where Entity Display Name starts from 'Z'.

select distinct e.Name, e.LogicalName, e.OriginalLocalizedName, OptionSetValue.Label
from MetadataSchema.Entity as e inner join
MetadataSchema.LocalizedLabel as OptionSetValue on (e.EntityId = OptionSetValue.ObjectId and
OptionSetValue.ObjectColumnName = 'LocalizedName')
where OptionSetValue.Label like 'Z%'
order by OptionSetValue.Label

With this we can easily get a list of entities and can do other necessary implementations in bulk. 


For example this is a good input to the query in below link,
http://matheeid.blogspot.com/2014/12/bulk-hide-entities-from-advance-find-in.html


Bulk Hide Entities from Advance Find in MS Dynamics CRM


Hello World,

If you are in trouble with unnecessary Entities in your Advance Find (that you created while ago and no longer needed) but you don't want to remove them. And you want to hide them from your customers. And you are too lazy and you want one query that works for all. :)
I was that lazy.

EntityMetadata.IsValidForAdvancedFind Property 

     - Gets or sets whether the entity will be shown in Advanced Find

if IsValidForAdvancedFind = 1 
then referring entity will be shown in Advance Find.


Therefore to hide a entity from Advance Find we can write - 

         update MetadataSchema.Entity
         set IsValidForAdvancedFind = 0
         where  Name = 'EntityName' 

Above will hide the contact  entity for all users  on the advanced.


Then to hide the Entity been displayed under related Entities we can write,

update MetadataSchema.Relationship 
set IsValidForAdvancedFind = 0
where ReferencingEntityId = (select MetadataSchema.Entity.EntityId 
    from MetadataSchema.Entity 
    where Name = 'EntityName') and IsValidForAdvancedFind  = 1)


If you have multiple Entities to update you can easily change the '=' to 'IN' and write all the Entities as a array.

update MetadataSchema.Entity 
set IsValidForAdvancedFind = 0 
where Name IN ('EntityName1', 'EntityName2', ......)


Hope this would be useful
Mathee