I
I
Ivan Melnikov2019-02-18 10:43:02
Python
Ivan Melnikov, 2019-02-18 10:43:02

How to get the value of the Document field in 1C query if this field has a reference type?

There is the following Python code that clings to the 1C database via a COM connection:

#coding=cp1251
import pythoncom
import win32com.client
V83_CONN_STRING = 'File="C:\\Users\\user\\Documents\\InfoBase\\";Usr="Иванов Иван";Pwd="123456";'
pythoncom.CoInitialize()
V83 = win32com.client.Dispatch("V83.COMConnector").Connect(V83_CONN_STRING)
q = '''
ВЫБРАТЬ
  ДатаЗапуска КАК DATESTART,
  Комментарий КАК KOMMENT,
  Организация КАК ORG
ИЗ
  Документ.ЗаказНаПроизводство
ГДЕ ДатаЗапуска МЕЖДУ ДАТАВРЕМЯ(2018, 12, 1, 0, 0, 0) И ДАТАВРЕМЯ(2018, 12, 5, 0, 0, 0)
'''
query = V83.NewObject("Query", q)
sel = query.Execute().Choose()
while sel.next():
    print(sel.DATESTART)
    print(sel.KOMMENT)
    print(sel.ORG)

The StartDate and Comment fields are of Date and String types, respectively, and are normally printed. And the Organization field is of type DirectoryReference. Organizations and the corresponding print() outputs >.
How can I get the values ​​of such fields in the Document?
And the second question. How to get the values ​​of the fields of the tabular part of the Document?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
K
Konstantin Nagibovich, 2019-02-18
@immelnikoff

Organization is of type DirectoryReference. Organizations and the corresponding print() outputs >.

If you are satisfied with the name of the organization, then do so;
SELECT *
FROM Document.TablePart AS Doc.WHERE
Doc.Ref = &ReferenceToDocument
I think you get the idea. Replace Document and TabularPart with the names you need.

D
Dmitry Kinash, 2019-02-18
@Dementor

Above, Konstantin wrote everything correctly. The organization from ProductionOrder is not a string, but an internal reference type, which has no match in python, and therefore standard output cannot cope with this value.
I suspect that it will be a COM object. If my hypothesis is correct, then it should work:
print(sel.ORG.Description)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question