Retrieve CRM Views Records using c# Plugin


Dynamics CRM

Hi ,

If we need to retrieve CRM Records based on Entity Views in Plugin (c#).

  • In CRM we have 2 tables , saved Query , User Query.

In Saved Query

  • Default Entity Based query
  • [ Eg: Account Entity à Views Active Views , In Active Views ,Etc.].
  • My Personal Views [Eg: User Personal Views ]

In User Query

  • User based views , Team Based Views.
  • In both the entity [ saved Query , User Query ] we have following fields
  • View Id = Unique View Id for both entity [ saved Query , User Query]
  • View Name = Name of the view
  • Fetchxml = A string field which stores the fetch xml query where we need add condition etc.
  • Query Type = Type of the query [eg 0 , 2]
  • Sample Code . .

Similarly

Retrieve  User Query Records

Thanks 🙂

View original post

Advertisements

Retrieve CRM Views Records using c# Plugin


Hi ,

If we need to retrieve CRM Records based on Entity Views in Plugin (c#).

  • In CRM we have 2 tables , saved Query , User Query.

In Saved Query

  • Default Entity Based query
  • [ Eg: Account Entity à Views Active Views , In Active Views ,Etc.].
  • My Personal Views [Eg: User Personal Views ]

In User Query

  • User based views , Team Based Views.
  • In both the entity [ saved Query , User Query ] we have following fields
  • View Id = Unique View Id for both entity [ saved Query , User Query]
  • View Name = Name of the view
  • Fetchxml = A string field which stores the fetch xml query where we need add condition etc.
  • Query Type = Type of the query [eg 0 , 2]
  • Sample Code . .

Retrieve  saved Query Records

Guid ViewId = new Guid("GUID OF VIEW");

var savedQueryFetchXml = (from q in orgContext.CreateQuery("savedquery")

where (Guid)q["savedqueryid"] == ViewId // We can pass Name of the view [Eg:(string)q["name"] = "VIEW NAME"
&& (string)q["fetchxml"] != null

select q["fetchxml"]).FirstOrDefault();

 

Similarly

Retrieve  User Query Records


var UserQueryFetchXml = (from q in orgContext.CreateQuery("userquery")

where (Guid)q["userqueryid"] == ViewId
&& (string)q["fetchxml"] != null

select q["fetchxml"]).FirstOrDefault();

Thanks 🙂