web
You’re offline. This is a read only version of the page.
close
Skip to main content
Community site session details

Community site session details

Session Id :
Dynamics 365 Community / Blogs / Dreaming in CRM / Three useful LINQ Queries

Three useful LINQ Queries

NatrajY Profile Picture NatrajY 3,040

In order to run these queries you’ll have to install LINQPad and LINQPad Driver for CRM.

Query 1 – Who created the entities?

It is not possible to look at an entity and find out who created it. You can however use the createdby on the SavedQuery (System View) to find out this information, as the System View is created the same time as the entity is created and also contains the createdby user information.

(from s in SavedQuerySet.AsEnumerable()
where s.QueryType == 0 && !s.IsManaged.Value && !s.CanBeDeleted.Value
orderby s.ReturnedTypeCode
group s by new {
Entity = s.ReturnedTypeCode,
CreatedBy = s.CreatedBy.Name
} into g
select g.Key)

entity-by-user

Query 2 – Entity creation timestamp

This is basically similar to the previous query, but this displays the createdon timestamp for the specified entity.

(from s in SavedQuerySet
where s.QueryType == 0 && s.ReturnedTypeCode == "[ENTITYNAME]"
orderby s.CreatedOn
select new { CreatedBy = s.CreatedBy.Name, CreatedOn = s.CreatedOn.Value.ToLocalTime(), s.ReturnedTypeCode }).Take(1)

Entity Creation Date.png

Query 3 – All Plugins with message, stage, filtering attributes and entity

You can use this query to get a quick snapshot of all the plugins in the system.

from m in SdkMessageProcessingStepSet
join f in SdkMessageFilterSet on m.SdkMessageFilterId.Id equals f.SdkMessageFilterId
join s in SdkMessageSet on f.SdkMessageId.Id equals s.SdkMessageId
join p in PluginTypeSet on m.PluginTypeId.Id equals p.PluginTypeId
where f.IsCustomProcessingStepAllowed.Value
&& !m.IsHidden.Value
&& m.CustomizationLevel.Value == 1
select new { Message = s.Name, Rank = m.Rank.Value, Stage = m.Stage, StageName = m.FormattedValues["stage"], m.FilteringAttributes, p.AssemblyName, PluginName= p.Name, StepName = m.Name, StepDescription = m.Description, Status = m.StatusCode, StatusName = m.FormattedValues["statuscode"]}

plugins



This was originally posted here.

Comments

*This post is locked for comments