public List <IView> GetPersonalViews(ISiteSetting siteSetting, CRMEntity entity) { Logger.Warning("GetPersonalViews 0", "GetPersonalViews"); List <IView> views = new List <IView>(); IOrganizationService organizationService = GetClientContext(siteSetting); // Dictionary to contain all the saved views Dictionary <Guid, Entity> dictPersonalViews = new Dictionary <Guid, Entity>(); // retrieve first all the CRM Users QueryExpression systemUsers = new QueryExpression("systemuser"); CamlFilters filters1 = new CamlFilters(); filters1.Add(new CamlFilter("isdisabled", FieldTypes.Text, CamlFilterTypes.Equals, "FALSE")); systemUsers.Criteria = GetFilterExpression(filters1); systemUsers.ColumnSet = new ColumnSet(true); EntityCollection userCollection = organizationService.RetrieveMultiple(systemUsers); Logger.Warning("GetPersonalViews 1", "GetPersonalViews"); Logger.Warning("Count:" + userCollection.Entities.Count, "GetPersonalViews"); int currentIndex = 0; // for each User we launch the query to retrieve the saved views foreach (Entity systemUser in userCollection.Entities) { try { currentIndex++; Logger.Warning("Index:" + currentIndex, "GetPersonalViews"); QueryExpression personalViews = new QueryExpression("userquery"); CamlFilters filters = new CamlFilters(); filters.Add(new CamlFilter("returnedtypecode", FieldTypes.Text, CamlFilterTypes.Equals, entity.LogicalName)); personalViews.Criteria = GetFilterExpression(filters); Logger.Warning("GetPersonalViews 2" + entity.LogicalName, "GetPersonalViews"); personalViews.ColumnSet = new ColumnSet(true); // we set the CallerId property to impersonate the current iteration user //Logger.Warning("GetPersonalViews 3" + entity.LogicalName, "GetPersonalViews"); ((OrganizationServiceProxy)organizationService).CallerId = systemUser.Id; //Logger.Warning("GetPersonalViews 4" + entity.LogicalName, "GetPersonalViews"); EntityCollection viewCollection = organizationService.RetrieveMultiple(personalViews); //Logger.Warning("GetPersonalViews 5" + entity.LogicalName, "GetPersonalViews"); foreach (Entity personalView in viewCollection.Entities) { // we want a list without duplicates (shared views or automatically shared to SYSTEM and INTEGRATION users) if (!dictPersonalViews.ContainsKey(personalView.Id)) { dictPersonalViews.Add(personalView.Id, personalView); } } } catch (Exception ex1) { Logger.Error(ex1, "GetPersonalViews"); } } Logger.Warning("GetPersonalViews 6" + entity.LogicalName, "GetPersonalViews"); // we can process the values (Entity objects) of the dictionary foreach (Entity personalView in dictPersonalViews.Values) { string viewName = personalView["name"].ToString(); string viewFetchXml = personalView["fetchxml"].ToString(); EntityReference viewOwnerIdRef = (EntityReference)personalView["ownerid"]; CRMView view = new CRMView(personalView.Id.ToString(), viewName, siteSetting.ID, entity); views.Add(view); } Logger.Warning("GetPersonalViews 7" + entity.LogicalName, "GetPersonalViews"); return(views); }
private void NavigateToCRMCommandExecuted() { WindowContent = new CRMView(); }