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

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

How to retrieve List of views related to Entity

(0) ShareShare
ReportReport
Posted on by 2,003

I have populated an option set with list of entities. Now i want to populate another option set with related Views to that particular entity. Is there any metadata class which i can use to retrieve views name or i have to query a SavedQueryBase Entity at the database.

*This post is locked for comments

I have the same question (0)
  • Verified answer
    Aileen Gusni Profile Picture
    44,524 on at

    Hi Abhishek,

     

    There is a way to retrieve the view through SDK not SQL, like what you did previously to retrieve the list of entities in previous post very well.

    Just to remember that there are 2 types of View in CRM entity based on View Ownership.

    One is Organization or System View, second is Individual, personal or User/Team View, those are stored in two different entities.

    System Views are stored in the SavedQuery entity, while User Views are stored in the UserQuery Entity, ok.

    You can combine RetrieveMultiple request against the savedquery entity (or userquery if you want to retrieve personal views as well) combined with QueryExpression + Filtering condition expression using returned type code, this is the code for each entity that youretrieved from your previous metada request, right.

    Example here:

    // Retrieve Views
                        QueryExpression mySavedQuery = new QueryExpression
                        {
                            ColumnSet = new ColumnSet("savedqueryid", "name", "querytype", "isdefault", "returnedtypecode", "isquickfindquery"),
                            EntityName = SavedQuery.EntityLogicalName,
                            Criteria = new FilterExpression
                            {
                                Conditions =
                {
                    new ConditionExpression
                    {
                        AttributeName = "querytype",
                        Operator = ConditionOperator.Equal,
                        Values = {0}
                    },
                    new ConditionExpression
                    {
                        AttributeName = "returnedtypecode",
                        Operator = ConditionOperator.Equal,
                        Values = {Opportunity.EntityTypeCode} //this is you can replace with 3 for Opportunity, replace this with each entity type code you retrieved before in your previous post, ok
                    }
                }
                            }
                        };
                        RetrieveMultipleRequest retrieveSavedQueriesRequest = new RetrieveMultipleRequest { Query = mySavedQuery };
    
                        RetrieveMultipleResponse retrieveSavedQueriesResponse = (RetrieveMultipleResponse)_serviceProxy.Execute(retrieveSavedQueriesRequest);
    
                        DataCollection<Entity> savedQueries = retrieveSavedQueriesResponse.EntityCollection.Entities;
    
                        //Display the Retrieved views
                        foreach (Entity ent in savedQueries)
                        {
                            SavedQuery rsq = (SavedQuery)ent;
                            Console.WriteLine("{0} : {1} : {2} : {3} : {4} : {5},", rsq.SavedQueryId, rsq.Name, rsq.QueryType, rsq.IsDefault, rsq.ReturnedTypeCode, rsq.IsQuickFindQuery);
                        }


    You can see the full code example here:

    https://msdn.microsoft.com/en-us/library/gg594431.aspx

    Other example:

    https://parthimscrm.wordpress.com/2014/09/09/retrieve-crm-views-records-using-c-plugin/

    You can also use LINQ to query retrieving the view.

    But the point here is to retrieve using SavedQuery entity using RetrieveMultipleRequest.

    Hope this helps, Abhishek.

    Thank you.

  • Abhishek Gupta Profile Picture
    2,003 on at

    Thanks Aileen :)

  • Community Member Profile Picture
    on at

    Hi Abhishek,

    What is the business flow for this specific requirement. How this information is used? 

    Aileen, As always, you are meticulous in providing solutions.

    harihar

  • Aileen Gusni Profile Picture
    44,524 on at

    Hi Harihar,

    Seems like Abhishek wants to build a custom app that can list the view.

    Just my opinion, btw. Thanks :)

  • Community Member Profile Picture
    on at

    Thank you Aileen for sharing your thoughts!

    best wishes,

    harihar

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
SA-08121319-0 Profile Picture

SA-08121319-0 4

#1
Calum MacFarlane Profile Picture

Calum MacFarlane 4

#3
Alex Fun Wei Jie Profile Picture

Alex Fun Wei Jie 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans