protected IEnumerable <IRecord> GetRecordsToProcess(bool selectedOnly)
        {
            IEnumerable <IRecord> recordsToUpdate = null;

            QueryViewModel.DynamicGridViewModel.LoadingViewModel.IsLoading      = true;
            QueryViewModel.DynamicGridViewModel.LoadingViewModel.LoadingMessage = "Loading Dialog";
            try
            {
                var fieldsToGet = new List <string>();
                fieldsToGet.Add(RecordService.GetPrimaryKey(QueryViewModel.RecordType));
                var primaryField = RecordService.GetPrimaryField(QueryViewModel.RecordType);
                if (!string.IsNullOrWhiteSpace(primaryField))
                {
                    fieldsToGet.Add(primaryField);
                }

                if (selectedOnly)
                {
                    var ids = QueryViewModel.DynamicGridViewModel.SelectedRows.Select(r => r.Record.Id).ToArray();
                    recordsToUpdate = RecordService.RetrieveAllOrClauses(QueryViewModel.RecordType, ids.Select(i => new Condition(RecordService.GetPrimaryKey(QueryViewModel.RecordType), ConditionType.Equal, i)), fieldsToGet);
                }
                else
                {
                    var getRecordsResults = QueryViewModel.GetGridRecords(true, fields: fieldsToGet);
                    recordsToUpdate = getRecordsResults.Records;
                }
            }
            finally
            {
                QueryViewModel.DynamicGridViewModel.LoadingViewModel.IsLoading = false;
            }

            return(recordsToUpdate);
        }