It is necessary to print out the data from the table part of the document in the printed form of the document. Tell me, how to make a request to the data of the document grounds for printing them? I wrote this code, but it does not work. Writes a field of goods not found (and in doc-the basis of it it definitely is)

Процедура Печать(ТабДок, Ссылка) Экспорт //{{_КОНСТРУКТОР_ПЕЧАТИ(Печать) Макет = Документы.ЗаявкаНаДоставку.ПолучитьМакет("Печать"); Запрос = Новый Запрос; Запрос.Текст = "ВЫБРАТЬ | ЗаявкаНаДоставку.АдресДоставки, | ЗаявкаНаДоставку.Водитель, | ЗаявкаНаДоставку.ВремяДоставки, | ЗаявкаНаДоставку.Грузополучатель, | ЗаявкаНаДоставку.Грузчик1, | ЗаявкаНаДоставку.Грузчик2, | ЗаявкаНаДоставку.Дата, | ЗаявкаНаДоставку.ДатаДоставки, | ЗаявкаНаДоставку.Номер, | ЗаявкаНаДоставку.ПробегКонечный, | ЗаявкаНаДоставку.СтатусДоставки, | ЗаявкаНаДоставку.ТелефонКонтактногоЛица, | ЗаявкаНаДоставку.ТС |ИЗ | Документ.ЗаявкаНаДоставку КАК ЗаявкаНаДоставку | ГДЕ | ЗаявкаНаДоставку.Ссылка В (&Ссылка) "; Запрос2 = Новый Запрос; Запрос2.Текст = "ВЫБРАТЬ | РеализацияТоваров1.Товары.( | НомерСтроки, | НаименованиеТовара, | ЕдИзм, | Количество, | Цена, | Сумма | ) |ИЗ | Документ.РеализацияТоваров1 КАК РеализацияТоваров1 |ГДЕ | РеализацияТоваров1.Ссылка В (&ДокументОснование)"; Запрос.Параметры.Вставить("Ссылка", Ссылка); Запрос2.Параметры.Вставить("Ссылка", Ссылка); Выборка = Запрос.Выполнить().Выбрать(); Выборка2 = Запрос2.Выполнить().Выбрать(); ОбластьЗаголовок = Макет.ПолучитьОбласть("Заголовок"); Шапка = Макет.ПолучитьОбласть("Шапка"); ОбластьТоварыШапка = Макет.ПолучитьОбласть("ТоварыШапка"); ОбластьТовары = Макет.ПолучитьОбласть("Товары"); ТабДок.Очистить(); ВставлятьРазделительСтраниц = Ложь; Пока Выборка.Следующий() ИЛИ Выборка2.Следующий() Цикл Если ВставлятьРазделительСтраниц Тогда ТабДок.ВывестиГоризонтальныйРазделительСтраниц(); КонецЕсли; ТабДок.Вывести(ОбластьЗаголовок); Шапка.Параметры.Заполнить(Выборка); ТабДок.Вывести(Шапка, Выборка.Уровень()); ТабДок.Вывести(ОбластьТоварыШапка); ВыборкаТовары = Выборка2.Товары.Выбрать(); Пока ВыборкаТовары.Следующий() Цикл ОбластьТовары.Параметры.Заполнить(ВыборкаТовары); ТабДок.Вывести(ОбластьТовары, ВыборкаТовары.Уровень()); КонецЦикла; ВставлятьРазделительСтраниц = Истина; КонецЦикла; //}} КонецПроцедуры 
  • I think the code is clearly broken logic. It's hard to say without seeing all the code. For example, what is contained in the variable "Sampling" and where the variable "Link" is defined ... - Ella Svetlaya
  • @ Ella Svetlaya put all the code. In request 2, I am trying to get data from the founding document. Generally displays nothing, gives an error - Elena
  • Describe which configuration is used, where in which requisite the foundation document is stored, which document is primary. Your second request is incorrect - it should be so SELECT * | FROM | Document.Realization of the Goods 1.Products AS the Realization of the Goods1 | WHERE | Realization of the Goods. Reference = & Document Basis - ivansoft
  • @ivansoft I’m trying to figure out 1c from scratch for the whole second week, so sorry for stupid questions. I thought that when we create a document on the basis of another, a reference to the doc. Justification should appear in it automatically. Isn't that right? I have to create a prop, where can I put the link to the doc. - Elena
  • @ivansoft made a change to the code as you wrote. It gives an error: "{Document.ApplicationDelivery.Manager module (46)}: Error when calling the context method (Run) Sampling2 = Request2. Execute (). Select (); due to: {(13, 28)}: The parameter value was not specified "Document " Realization of the = <<? >> & Document " - Elena

1 answer 1

A few notes on the code:

  1. OrderDelivery. Link B (& Link) - it is meaningless to use B, if in the parameter - one document. OrderDelivery.Link = & Link.

  2. In the second request, there is no Link parameter, but for some reason it is set. On the other hand, the necessary Document Document parameter is not set.

  3. Try to get all the data you need to receive in one request. If you have completely different data in the requests - do a few, but in a batch request. This improves performance by reducing the number of calls to the database.

  4. The answer to your comment is yes, in order for the document to be in another document, you need to create the requisite in this document and you need to make sure that this requisite is filled in in the code yourself.

  5. Without a complete description of what you want, it is difficult to help you. What data should be obtained from the document, and which - from its basis? What is the relationship between them? The general scheme of the request approximately meets your conditions:

ВЫБРАТЬ ВозвратДенег.Ссылка КАК ДокументВозвратДенег, ВозвратДенег.Валюта КАК Валюта, ВозвратДенег.Контрагент КАК Контрагент, ВозвратДенег.Дата, ДенежныеРасходыРасходы.СтатьяРасходов, ДенежныеРасходыРасходы.Сумма, ДенежныеРасходыРасходы.Ссылка КАК ДокументДенежныеРасходы ИЗ Документ.ВозвратДенег КАК ВозвратДенег ЛЕВОЕ СОЕДИНЕНИЕ Документ.ДенежныеРасходы.Расходы КАК ДенежныеРасходыРасходы ПО ВозвратДенег.ДокументОснование = ДенежныеРасходыРасходы.Ссылка ИТОГИ МАКСИМУМ(Валюта), МАКСИМУМ(Контрагент) ПО ДокументВозвратДенег

Explanations - Returning Money here is a document, and Cash Expenses are the basis. The link to the base is stored in the Document base, you see this in the link condition. Results here in order to get a two-tier tree - at the top level there will be a document Return Money and its details. Please note - all its details are listed in the section RESULTS . This is so that they are displayed at the top level. The rest of the details - the details of the document base, will be on the second level of the tree. The round is done like this

 РезультатЗапроса = Запрос.Выполнить(); ВыборкаДокументВозвратДенег = РезультатЗапроса.Выбрать(ОбходРезультатаЗапроса.ПоГруппировкам); Пока ВыборкаДокументВозвратДенег.Следующий() Цикл // Вставить обработку выборки ВыборкаДокументВозвратДенег ВыборкаДетальныеЗаписи = ВыборкаДокументВозвратДенег.Выбрать(); Пока ВыборкаДетальныеЗаписи.Следующий() Цикл // Вставить обработку выборки ВыборкаДетальныеЗаписи КонецЦикла; КонецЦикла; 
  • I'm sorry, I just looked, I haven't been here in a while. - Elena