public QueryDefinition GenerateQuery() { var query = new QueryDefinition(RecordType); query.Distinct = true; if (IsQuickFind) { query.IsQuickFind = true; query.QuickFindText = QuickFindText; if (!string.IsNullOrWhiteSpace(QuickFindText)) { var quickFindFields = RecordService.GetStringQuickfindFields(RecordType); //there was a bug in SDK when querying on queues //which required adding our or filter as a child filter //rather than adding in the root filter var nestedFilter = new Filter(); nestedFilter.ConditionOperator = FilterOperator.Or; nestedFilter.Conditions.AddRange(quickFindFields.Select(f => new Condition(f, ConditionType.BeginsWith, QuickFindText))); query.RootFilter.SubFilters.Add(nestedFilter); } } else { query.RootFilter = FilterConditions.GetAsFilter(); query.Joins = Joins.GetAsJoins().ToList(); } var view = DynamicGridViewModel.RecordService.GetView(DynamicGridViewModel.RecordType, DynamicGridViewModel.ViewType); query.Sorts = view.Sorts.ToList(); return(query); }
public QueryDefinition GenerateQuery() { var query = new QueryDefinition(RecordType); query.Distinct = true; if (IsQuickFind) { query.IsQuickFind = true; query.QuickFindText = QuickFindText; if (!string.IsNullOrWhiteSpace(QuickFindText)) { var quickFindFields = RecordService.GetStringQuickfindFields(RecordType); query.RootFilter.ConditionOperator = FilterOperator.Or; query.RootFilter.Conditions.AddRange(quickFindFields.Select(f => new Condition(f, ConditionType.BeginsWith, QuickFindText))); } } else { query.RootFilter = FilterConditions.GetAsFilter(); query.Joins = Joins.GetAsJoins().ToList(); } var view = DynamicGridViewModel.RecordService.GetView(DynamicGridViewModel.RecordType, DynamicGridViewModel.ViewType); query.Sorts = view.Sorts.ToList(); return(query); }
public QueryDefinition GenerateQuery() { var query = new QueryDefinition(RecordType); query.Distinct = true; if (IsQuickFind) { query.IsQuickFind = true; query.QuickFindText = QuickFindText; if (!string.IsNullOrWhiteSpace(QuickFindText)) { var quickFindFields = RecordService.GetStringQuickfindFields(RecordType); //there was a bug in SDK when querying on queues //which required adding our or filter as a child filter //rather than adding in the root filter var nestedFilter = new Filter(); nestedFilter.ConditionOperator = FilterOperator.Or; nestedFilter.Conditions.AddRange(quickFindFields.Select(f => new Condition(f, ConditionType.BeginsWith, QuickFindText))); query.RootFilter.SubFilters.Add(nestedFilter); } } else { query.RootFilter = FilterConditions.GetAsFilter(); query.Joins = Joins.GetAsJoins().ToList(); } var view = DynamicGridViewModel.RecordService.GetView(DynamicGridViewModel.RecordType, DynamicGridViewModel.ViewType); query.Sorts = view.Sorts.Where(s => !s.FieldName.Contains(".")).ToList(); //okay lets add joins for all the columns in referenced types if (ExplicitlySelectedColumns != null) { var linkGroups = ExplicitlySelectedColumns .Where(c => c.AliasedFieldName != null) .GroupBy(c => c.AliasedFieldName.Split('.')[0]); foreach (var linkGroup in linkGroups) { var joinToRecordType = linkGroup.First().AltRecordType; var lookupField = linkGroup.Key.Substring(0, linkGroup.Key.Length - (joinToRecordType.Length + 1)); var join = new Join(lookupField, joinToRecordType, RecordService.GetPrimaryKey(joinToRecordType)); join.JoinType = JoinType.LeftOuter; join.Fields = linkGroup.Select(lgf => lgf.FieldName); join.Alias = linkGroup.Key; query.Joins.Add(join); } } return(query); }
public QueryDefinition GenerateQuery() { var query = new QueryDefinition(RecordType); if (IsQuickFind) { query.IsQuickFind = true; query.QuickFindText = QuickFindText; if (!string.IsNullOrWhiteSpace(QuickFindText)) { query.RootFilter.Conditions.Add(new Condition(RecordService.GetPrimaryField(DynamicGridViewModel.RecordType), ConditionType.BeginsWith, QuickFindText)); } } else { query.RootFilter = FilterConditions.GetAsFilter(); } var view = DynamicGridViewModel.RecordService.GetView(DynamicGridViewModel.RecordType, DynamicGridViewModel.ViewType); query.Sorts = view.Sorts.ToList(); return(query); }
public QueryDefinition GenerateQuery() { var query = new QueryDefinition(RecordType); query.Distinct = true; if (IsQuickFind) { query.IsQuickFind = true; query.QuickFindText = QuickFindText; if (!string.IsNullOrWhiteSpace(QuickFindText)) { var quickFindFields = RecordService.GetStringQuickfindFields(RecordType); //there was a bug in SDK when querying on queues //which required adding our or filter as a child filter //rather than adding in the root filter var nestedFilter = new Filter(); nestedFilter.ConditionOperator = FilterOperator.Or; nestedFilter.Conditions.AddRange(quickFindFields.Select(f => new Condition(f, ConditionType.BeginsWith, QuickFindText))); query.RootFilter.SubFilters.Add(nestedFilter); } } else { query.RootFilter = FilterConditions.GetAsFilter(); query.Joins = Joins.GetAsJoins().ToList(); } var view = DynamicGridViewModel.RecordService.GetView(DynamicGridViewModel.RecordType, DynamicGridViewModel.ViewType); query.Sorts = view.Sorts.Where(s => !s.FieldName.Contains(".")).ToList(); //okay lets add joins for all the columns in referenced types if (ExplicitlySelectedColumns != null) { var linkGroups = ExplicitlySelectedColumns .Where(c => c.AliasedFieldName != null) .GroupBy(c => c.AliasedFieldName.Split('.')[0]); foreach (var linkGroup in linkGroups) { var joinToRecordType = linkGroup.First().AltRecordType; var lookupField = linkGroup.Key.Substring(0, linkGroup.Key.Length - (joinToRecordType.Length + 1)); var join = new Join(lookupField, joinToRecordType, RecordService.GetPrimaryKey(joinToRecordType)); join.JoinType = JoinType.LeftOuter; join.Fields = linkGroup.Select(lgf => lgf.FieldName); join.Alias = linkGroup.Key; query.Joins.Add(join); } } //for whatever reason the dynamics web service throws an error //if you query for distinct with an activity party field explicitly included //so only limit fields in the query if no activity parties included var fieldsRequiredInQuery = ExplicitlySelectedColumns ?? view.Fields.Select(f => new GridFieldMetadata(f)).ToList(); var includeAll = false; foreach (var field in fieldsRequiredInQuery) { if (RecordService.GetFieldType(field.FieldName, field.AltRecordType ?? RecordType) == RecordFieldType.ActivityParty) { includeAll = true; break; } } if (!includeAll) { query.Fields = fieldsRequiredInQuery.Where(f => f.AltRecordType == null).Select(f => f.FieldName).ToArray(); } return(query); }