G
G
GIRU2020-07-09 23:21:09
1C
GIRU, 2020-07-09 23:21:09

How to sort query result by given field?

good evening! There is such a request

Функция ПолучитьАнкетуПоИмени(urlФормы)
  
  
   
  Запрос = Новый Запрос;
    
  Запрос.Текст = "ВЫБРАТЬ
                 |	ВопросыШаблонаАнкеты.Ссылка КАК Ссылка,
                 |	ВЫБОР
                 |		КОГДА ВопросыШаблонаАнкеты.ТипВопроса = ЗНАЧЕНИЕ(Перечисление.ТипыВопросовШаблонаАнкеты.Табличный)
                 |			ТОГДА ВопросыШаблонаАнкеты.JSON
                 |		ИНАЧЕ ВопросыШаблонаАнкеты.ЭлементарныйВопрос.JSON
                 |	КОНЕЦ КАК JSON
                 |ИЗ
                 |	Справочник.ВопросыШаблонаАнкеты КАК ВопросыШаблонаАнкеты
                 |ГДЕ
                 |	ВопросыШаблонаАнкеты.ЭтоГруппа = ЛОЖЬ
                 |	И ВопросыШаблонаАнкеты.Владелец.Ссылка В
                 |			(ВЫБРАТЬ
                 |				ФормированиеЧПУ.ШаблоныАнкет
                 |			ИЗ
                 |				РегистрСведений.ФормированиеЧПУ КАК ФормированиеЧПУ
                 |			ГДЕ
                 |				ФормированиеЧПУ.URL = &URL)";
  
  Запрос.УстановитьПараметр("URL", urlФормы);
  
  МассивJSON = Новый Массив();
  МассивJSON = Запрос.Выполнить().Выгрузить().ВыгрузитьКолонку("JSON");
  
  ВыходнаяСтрока = СтрСоединить(МассивJSON, ",");
    
  Возврат ВыходнаяСтрока;

It returns the questions of the questionnaire template in a scatter, but it should be in the same order as in the picture 5f07781f1c433131188074.png
. That is, there are numbers in the questionnaire template, but I can’t figure out how to sort by this field. Those. I make different requests and I can't see this numbering in the request console, I don't understand where and how it is located. Question: How to find, display this numbering in the query and sort by it?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
Dmitry Kinash, 2020-07-10
@Dementor

That is, there are numbers in the questionnaire template, but I can’t figure out how to sort by this field. Those. I make different requests and I can't see this numbering in the request console, I don't understand where and how it is located.

Judging by the text of your request, all your data is stored in JSON format. Therefore, a request to 1C data will not work for you. Additional algorithmic data processing is needed.
JSON Array = New Array();
JSON array = Request.Execute().Upload().UploadColumn("JSON");

Let's look here. First, you create an object of type Array in memory in vain, since in the next operation you create a new array and put a reference to it in your variable. Thus, the number of references to the first array is reset to zero and it waits for the remaining time for the garbage collector to arrive.
Next, you can simply upload the value table and do not need to upload the JSON column from it. Then you need to add a new column to this table for the field you want to sort by. Next, loop through the rows of your table, create JSON objects by text, and throw the values ​​of the sort fields into the columns you created. After passing through the loop, call the Sort() method by the columns you need in the desired direction. And now you can call UnloadColumn("JSON") on your table - and there will be data that is sorted exactly as you need.

K
Konstantin Nagibovich, 2020-07-10
@nki

Find the attribute that contains the question number and sort by it.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question