<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
	<channel>
		<title><![CDATA[Форум компьютерной помощи &mdash; Синхронизация документов в двух базах]]></title>
		<link>https://itpmr.ru/viewtopic.php?id=1121</link>
		<atom:link href="https://itpmr.ru/extern.php?action=feed&amp;tid=1121&amp;type=rss" rel="self" type="application/rss+xml" />
		<description><![CDATA[Недавние сообщения в теме «Синхронизация документов в двух базах».]]></description>
		<lastBuildDate>Mon, 24 Oct 2022 13:25:25 +0000</lastBuildDate>
		<generator>PunBB</generator>
		<item>
			<title><![CDATA[Re: Синхронизация документов в двух базах]]></title>
			<link>https://itpmr.ru/viewtopic.php?pid=124880#p124880</link>
			<description><![CDATA[<p>Function Resp (adoc As NotesDocument) As Variant<br />&nbsp; &nbsp; Dim adrdoc As NotesDocument,&nbsp; respdoc As NotesDocument<br />&nbsp; &nbsp; Dim maindoc As NotesDocument, doc As NotesDocument&nbsp; &nbsp; <br />&nbsp; &nbsp; Dim dc As NotesDocumentCollection<br />&nbsp; &nbsp; Dim stsubdivision As String<br />&nbsp; &nbsp; &#039;&nbsp; &nbsp; adoc - орг в БД Адресаты,&nbsp; форма &quot;forg&quot;<br />&nbsp; &nbsp; &#039;&nbsp; respdoc - ответ в БД Адресаты, форма &quot;forg_resp&quot;, type_adr=2 у чела, type_adr=1 - у орг, Server_id 501<br />&nbsp; &nbsp; &#039;&nbsp; maindoc - главный в ВЭД, форма &quot;ref_orgs&quot;<br />&nbsp; &nbsp; &#039; doc - ответ в ВЭД, форма &quot;ref_orgs&quot;<br />&nbsp; &nbsp; On Error GoTo errh&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />&nbsp; &nbsp; &#039;Print &quot;Function Resp&quot;<br />&nbsp; &nbsp; Set&nbsp; &nbsp; maindoc = view.GetDocumentByKey(adoc.UniversalID)<br />&nbsp; &nbsp; If maindoc Is Nothing Then<br />&nbsp; &nbsp; &nbsp; &nbsp; Print &quot;нет главного в ВЭД для &quot;&nbsp; adoc.Server_name(0)<br />&nbsp; &nbsp; &nbsp; &nbsp; Exit Function<br />&nbsp; &nbsp; End If <br />&nbsp; &nbsp; <br />&nbsp; &nbsp; Set dc = adoc.Responses &#039;&nbsp; ответы с БД Адресаты<br />&nbsp; &nbsp; If Not dc Is Nothing Then<br />&nbsp; &nbsp; &nbsp; &nbsp; Set respdoc = dc.GetFirstDocument&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />&nbsp; &nbsp; &nbsp; &nbsp; While Not respdoc Is Nothing<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; i=i+1<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Set doc=view.GetDocumentByKey(respdoc.UniversalID) &#039; ищем в ВЭД док-ОТвет с бд Адресаты<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; If doc Is Nothing Then <br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Set doc=db.CreateDocument : doc.form=&quot;ref_orgs&quot; &#039; создали в ВЭД<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; End If<br />&nbsp; &nbsp; <br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; If respdoc.form(0)=&quot;forg_resp&quot;&nbsp; Then&nbsp; &#039;Руководитель ФИО, или подвед в БД Адресаты (всегда)<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; If doc.modify(0)&lt;&gt; respdoc.LastModified Then<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Print i &quot;. обновили respdoc &quot; respdoc.Server_name(0)<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; doc.donorid=respdoc.Universal_ID(0)<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; doc.modify=respdoc.LastModified<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; doc.flag_not_visible=respdoc.flag_not_visible<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; doc.Server_name=respdoc.Server_name &#039; ФИО, или назв орг подведа.<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; doc.type_adr =respdoc.type_adr&nbsp; &#039; в БД адресаты у орг подведа - 1, а у человека - 2. <br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; doc.Server_id=respdoc.Server_id<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; If adoc.type_adr(0)=&quot;1&quot; Then &#039; код подведа у адресата родителя в БД Адресаты<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; stsubdivision$&nbsp; &nbsp; = adoc.Server_id(0)<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; respdoc.sts = stsubdivision$&nbsp; &nbsp; <br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Print &quot;подвед ЧЕЛ &quot; stsubdivision$&nbsp; &nbsp; <br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; End If<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; doc.nam=maindoc.nam&nbsp; &nbsp;&#039; Наименование организации&nbsp; <br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; doc.shnam=maindoc.shnam &#039; краткое Наименование организации&nbsp; <br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; doc.code=maindoc.code&nbsp; &nbsp;&#039;&nbsp; &nbsp;Код организации в МЭД<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; doc.xmlstr=&quot;&lt;destination&gt;&lt;legalentity&gt;&lt;kodorgout&gt;&quot;+doc.code(0)+&quot;&lt;/kodorgout&gt;&lt;nameorg&gt;&quot;+doc.nam(0)+&quot;&lt;/nameorg&gt;&lt;structuralsubdivision&gt;&quot; + stsubdivision$ +&quot;&lt;/structuralsubdivision&gt;&lt;post&gt;&quot;+doc.Server_name(0)+&quot;&lt;/post&gt;&lt;/legalentity&gt;&lt;/destination&gt;&quot;&nbsp; &nbsp; &nbsp; &nbsp; <br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Call doc.MakeResponse(maindoc)&nbsp; &nbsp; &nbsp; &nbsp; <br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Call doc.ComputeWithForm(1,0)<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Call doc.Save(1,0)<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Sleep 1<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; End If <br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; End If&nbsp; &nbsp; <br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Call Resp (respdoc) &#039;&nbsp; рекурсия<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Set respdoc = dc.GetNextDocument(respdoc)&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />&nbsp; &nbsp; &nbsp; &nbsp; Wend<br />&nbsp; &nbsp; End If<br />&nbsp; &nbsp; <br />&nbsp; &nbsp; Exit Function<br />errh:<br />&nbsp; &nbsp; Print &quot;Ошибка&nbsp; Resp&quot; &amp; Error(Err) &amp; &quot; в строке &quot; &amp; Erl&nbsp; &nbsp; <br />&nbsp; &nbsp; Exit Function<br />End Function</p>]]></description>
			<author><![CDATA[null@example.com (admin)]]></author>
			<pubDate>Mon, 24 Oct 2022 13:25:25 +0000</pubDate>
			<guid>https://itpmr.ru/viewtopic.php?pid=124880#p124880</guid>
		</item>
		<item>
			<title><![CDATA[Re: Синхронизация документов в двух базах]]></title>
			<link>https://itpmr.ru/viewtopic.php?pid=124879#p124879</link>
			<description><![CDATA[<p>Вторая версия с реккурсией.</p><p>%REM<br />&nbsp; &nbsp; Agent adrefresh<br />&nbsp; &nbsp; Created Jun 23, 2022 by Administrator NYY FGR/fond<br />&nbsp; &nbsp; Description: Comments for Agent<br />%END REM<br />Option Public<br />Option Declare</p><br /><p>Dim db As NotesDatabase<br />Dim view As NotesView<br />Dim i As Integer</p><p>Sub Initialize<br />&nbsp; &nbsp; Dim session As New NotesSession<br />&nbsp; &nbsp; Dim adrdoc As NotesDocument<br />&nbsp; &nbsp; Dim doc As NotesDocument<br />&nbsp; &nbsp; Dim adrdb As NotesDatabase<br />&nbsp; &nbsp; Dim adrview As NotesView<br />&nbsp; &nbsp; <br />&nbsp; &nbsp; Dim tmp_doc As NotesDocument<br />&nbsp; &nbsp; Print &quot;adrefresh2 START&quot;<br />&nbsp; &nbsp; On Error GoTo ErrH&nbsp; &nbsp; <br />&nbsp; &nbsp; i=0<br />&nbsp; &nbsp; Set db=session.Currentdatabase<br />&nbsp; &nbsp; Set view=db.GetView(&quot;reforgs3&quot;)&nbsp; &#039; Адресаты МЭД по donorid в БД ВЭД<br />&nbsp; &nbsp; Set adrdb=session.GetDatabase(&quot;fgrmed/Fgr&quot;,&quot;promdoc\adress.nsf&quot;, False)<br />&nbsp; &nbsp; If adrdb Is Nothing Then Print &quot;no connection with fgrmed/Fgr !&quot; Else Print &quot;fgrmed/Fgr connection OK!&quot;<br />&nbsp; &nbsp; Set adrview=adrdb.GetView(&quot;all&quot;)&nbsp; &nbsp; </p><p>&nbsp; &nbsp; Set adrdoc=adrview.GetFirstDocument&nbsp; &nbsp; &#039; док в БД Адресаты<br />&nbsp; &nbsp; While Not adrdoc Is Nothing&nbsp; &nbsp; <br />&nbsp; &nbsp; &nbsp; &nbsp; If adrdoc.form(0)=&quot;forg&quot; Then &#039;Организация в БД Адресаты<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; i=i+1<br />&nbsp; &nbsp; &nbsp; &nbsp; <br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Set doc=view.GetDocumentByKey(adrdoc.UniversalID) &#039; ищем в ВЭД док с бд Адресаты.<br />&nbsp; &nbsp; &nbsp; &nbsp; <br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; If doc Is Nothing Then <br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Set doc=db.CreateDocument : doc.form=&quot;ref_orgs&quot; &#039; создали в ВЭД<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; End If&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; If doc.modify(0)&lt;&gt; adrdoc.LastModified Then &#039; изменена Организация<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Sleep 1<br />&nbsp; &nbsp; &nbsp; &nbsp; Print&nbsp; i &quot;. Modified forg &quot; adrdoc.Server_name(0)<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; doc.donorid=adrdoc.Universal_ID(0)<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; doc.modify=adrdoc.LastModified&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; doc.flag_not_visible=adrdoc.flag_not_visible<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; doc.delete=CStr(adrdoc.delete(0))<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; doc.Server_name=adrdoc.Server_name &#039; во вью ref_orgs3 - для отображения.<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; doc.nam=adrdoc.Server_name&nbsp; &#039; назв Орг<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; doc.shnam=doc.nam<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; doc.code=adrdoc.Server_id<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; doc.xmlstr=&quot;&lt;destination&gt;&lt;legalentity&gt;&lt;kodorgout&gt;&quot;+doc.code(0)+&quot;&lt;/kodorgout&gt;&lt;nameorg&gt;&quot;+doc.nam(0)+&quot;&lt;/nameorg&gt;&lt;structuralsubdivision&gt;&lt;/structuralsubdivision&gt;&lt;post&gt;&quot;+doc.nam(0)+&quot;&lt;/post&gt;&lt;/legalentity&gt;&lt;/destination&gt;&quot;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Call doc.ComputeWithForm(1,0)&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Call doc.Save(1,0)<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; End If&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Call Resp (adrdoc)<br />&nbsp; &nbsp; &nbsp; &nbsp; End If&nbsp; &nbsp; &nbsp; &nbsp; <br />&nbsp; &nbsp; &nbsp; &nbsp; <br />&nbsp; &nbsp; &nbsp; &nbsp; Set adrdoc=adrview.GetNextDocument(adrdoc)<br />&nbsp; &nbsp; Wend&nbsp; &nbsp; <br />&nbsp; &nbsp; <br />&nbsp; &nbsp; Print &quot;конец&quot;<br />&nbsp; &nbsp; Print &quot;всего: &quot; i<br />&nbsp; &nbsp; Exit Sub<br />ErrH:<br />&nbsp; &nbsp; Print &quot;Ошибка АДРЕСАТЫ &quot; &amp; Error(Err) &amp; &quot; в строке &quot; &amp; Erl&nbsp; &nbsp; <br />&nbsp; &nbsp; Exit Sub<br />End Sub<br />Function Resp (adoc As NotesDocument) As Variant<br />&nbsp; &nbsp; Dim adrdoc As NotesDocument,&nbsp; respdoc As NotesDocument<br />&nbsp; &nbsp; Dim maindoc As NotesDocument, doc As NotesDocument&nbsp; &nbsp; <br />&nbsp; &nbsp; Dim dc As NotesDocumentCollection<br />&nbsp; &nbsp; Dim stsubdivision As String<br />&nbsp; &nbsp; &#039;&nbsp; &nbsp; adoc - орг в БД Адресаты,&nbsp; форма &quot;forg&quot;<br />&nbsp; &nbsp; &#039;&nbsp; respdoc - ответ в БД Адресаты, форма &quot;forg_resp&quot;, type_adr=2 у чела, type_adr=1 - у орг, Server_id 501<br />&nbsp; &nbsp; &#039;&nbsp; maindoc - главный в ВЭД, форма &quot;ref_orgs&quot;<br />&nbsp; &nbsp; &#039; doc - ответ в ВЭД, форма &quot;ref_orgs&quot;<br />&nbsp; &nbsp; On Error GoTo errh&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />&nbsp; &nbsp; &#039;Print &quot;Function Resp&quot;<br />&nbsp; &nbsp; Set&nbsp; &nbsp; maindoc = view.GetDocumentByKey(adoc.UniversalID)<br />&nbsp; &nbsp; If maindoc Is Nothing Then<br />&nbsp; &nbsp; &nbsp; &nbsp; Print &quot;нет главного в ВЭД для &quot;&nbsp; adoc.Server_name(0)<br />&nbsp; &nbsp; &nbsp; &nbsp; Exit Function<br />&nbsp; &nbsp; End If <br />&nbsp; &nbsp; <br />&nbsp; &nbsp; Set dc = adoc.Responses &#039;&nbsp; ответы с БД Адресаты<br />&nbsp; &nbsp; If Not dc Is Nothing Then<br />&nbsp; &nbsp; &nbsp; &nbsp; Set respdoc = dc.GetFirstDocument&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />&nbsp; &nbsp; &nbsp; &nbsp; While Not respdoc Is Nothing<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; i=i+1<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Set doc=view.GetDocumentByKey(respdoc.UniversalID) &#039; ищем в ВЭД док-ОТвет с бд Адресаты<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; If doc Is Nothing Then <br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Set doc=db.CreateDocument : doc.form=&quot;ref_orgs&quot; &#039; создали в ВЭД<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; End If<br />&nbsp; &nbsp; <br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; If respdoc.form(0)=&quot;forg_resp&quot;&nbsp; Then&nbsp; &#039;Руководитель ФИО, или подвед в БД Адресаты (всегда)<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; If doc.modify(0)&lt;&gt; respdoc.LastModified Then<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Print i &quot;. обновили respdoc &quot; respdoc.Server_name(0)<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; doc.donorid=respdoc.Universal_ID(0)<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; doc.modify=respdoc.LastModified<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; doc.flag_not_visible=respdoc.flag_not_visible<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; doc.Server_name=respdoc.Server_name &#039; ФИО, или назв орг подведа.<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; doc.type_adr =respdoc.type_adr&nbsp; &#039; в БД адресаты у орг подведа - 1, а у человека - 2. <br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; doc.Server_id=respdoc.Server_id<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; If adoc.type_adr(0)=&quot;1&quot; Then &#039; код подведа у адресата родителя в БД Адресаты<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; stsubdivision$&nbsp; &nbsp; = adoc.Server_id(0)<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; respdoc.sts = stsubdivision$&nbsp; &nbsp; <br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Print &quot;подвед ЧЕЛ &quot; stsubdivision$&nbsp; &nbsp; <br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; End If<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; doc.nam=maindoc.nam&nbsp; &nbsp;&#039; Наименование организации&nbsp; <br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; doc.shnam=maindoc.shnam &#039; краткое Наименование организации&nbsp; <br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; doc.code=maindoc.code&nbsp; &nbsp;&#039;&nbsp; &nbsp;Код организации в МЭД<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; doc.xmlstr=&quot;&lt;destination&gt;&lt;legalentity&gt;&lt;kodorgout&gt;&quot;+doc.code(0)+&quot;&lt;/kodorgout&gt;&lt;nameorg&gt;&quot;+doc.nam(0)+&quot;&lt;/nameorg&gt;&lt;structuralsubdivision&gt;&quot; + stsubdivision$ +&quot;&lt;/structuralsubdivision&gt;&lt;post&gt;&quot;+doc.Server_name(0)+&quot;&lt;/post&gt;&lt;/legalentity&gt;&lt;/destination&gt;&quot;&nbsp; &nbsp; &nbsp; &nbsp; <br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Call doc.MakeResponse(maindoc)&nbsp; &nbsp; &nbsp; &nbsp; <br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Call doc.ComputeWithForm(1,0)<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Call doc.Save(1,0)<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Sleep 1<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; End If <br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; End If&nbsp; &nbsp; <br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Call Resp (respdoc) &#039;&nbsp; рекурсия<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Set respdoc = dc.GetNextDocument(respdoc)&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />&nbsp; &nbsp; &nbsp; &nbsp; Wend<br />&nbsp; &nbsp; End If<br />&nbsp; &nbsp; <br />&nbsp; &nbsp; Exit Function<br />errh:<br />&nbsp; &nbsp; Print &quot;Ошибка&nbsp; Resp&quot; &amp; Error(Err) &amp; &quot; в строке &quot; &amp; Erl&nbsp; &nbsp; <br />&nbsp; &nbsp; Exit Function<br />End Function</p>]]></description>
			<author><![CDATA[null@example.com (admin)]]></author>
			<pubDate>Mon, 24 Oct 2022 13:25:18 +0000</pubDate>
			<guid>https://itpmr.ru/viewtopic.php?pid=124879#p124879</guid>
		</item>
		<item>
			<title><![CDATA[Синхронизация документов в двух базах]]></title>
			<link>https://itpmr.ru/viewtopic.php?pid=124878#p124878</link>
			<description><![CDATA[<p>Агент для синхронизации</p><div class="codebox"><pre><code>%REM
    Agent adrefresh
    Created Jun 23, 2022 by Administrator NYY FGR/fond
    Description: Comments for Agent
%END REM
Option Public
Option Declare

Sub Initialize
    Dim session As New NotesSession
    Dim db As NotesDatabase, adrdb As NotesDatabase
    Dim view As NotesView, adrview As NotesView
    Dim doc As NotesDocument, maindoc As NotesDocument, adrdoc As NotesDocument, mainadrdoc As NotesDocument
    Dim formula As String
    Dim l1 As Variant,  l2 As Variant
    Dim isnewd As Boolean
    Dim i As Integer, x As Integer
    Dim mainadrid As String, fla As String, del As String, stsubdivision As String, sts As String
    On Error GoTo ErrH    
    i=0
    Set db=session.Currentdatabase
    Set view=db.GetView(&quot;reforgs3&quot;)  &#039; Адресаты МЭД по donorid в БД ВЭД
    Set adrdb=session.GetDatabase(&quot;fgrmed/Fgr&quot;,&quot;promdoc\adress.nsf&quot;, False)
    If adrdb Is Nothing Then Print &quot;no connection with fgrmed/Fgr !&quot; Else Print &quot;fgrmed/Fgr connection OK!&quot;
    Set adrview=adrdb.GetView(&quot;all&quot;)
    
    For x= 1 To 2
        Set adrdoc=adrview.GetFirstDocument    &#039; док в БД Адресаты
        While Not adrdoc Is Nothing    
            Set doc=view.GetDocumentByKey(adrdoc.UniversalID) &#039; ищем в ВЭД док с бд Адресаты по donorid.
            If doc Is Nothing Then 
                Set doc=db.CreateDocument : doc.form=&quot;ref_orgs&quot; &#039; создали в ВЭД
            Else
                If doc.modify(0)= adrdoc.LastModified Then GoTo l1 &#039;пропустить неизмененные документы
            End If
            i=i+1
            Print  i &quot;.&quot; adrdoc.Server_name(0)
            If adrdoc.form(0)=&quot;forg&quot; And x =1 Then &#039;Организация в БД Адресаты
                doc.donorid=adrdoc.Universal_ID(0)
                doc.modify=adrdoc.LastModified            
                doc.flag_not_visible=adrdoc.flag_not_visible
                doc.delete=CStr(adrdoc.delete(0))
                doc.Server_name=adrdoc.Server_name &#039; во вью ref_orgs3 - для отображения.
                doc.nam=adrdoc.Server_name  &#039; назв Орг
                doc.shnam=doc.nam
                doc.code=adrdoc.Server_id
                doc.xmlstr=&quot;&lt;destination&gt;&lt;legalentity&gt;&lt;kodorgout&gt;&quot;+doc.code(0)+&quot;&lt;/kodorgout&gt;&lt;nameorg&gt;&quot;+doc.nam(0)+&quot;&lt;/nameorg&gt;&lt;structuralsubdivision&gt;&lt;/structuralsubdivision&gt;&lt;post&gt;&quot;+doc.nam(0)+&quot;&lt;/post&gt;&lt;/legalentity&gt;&lt;/destination&gt;&quot;
                Call doc.ComputeWithForm(1,0)            
                Call doc.Save(1,0)
            End If
            Sleep 1
            
            If adrdoc.form(0)=&quot;forg_resp&quot; And x =2 Then  &#039;Руководитель ФИО, или подвед в БД Адресаты 
                doc.donorid=adrdoc.Universal_ID(0)
                doc.modify=adrdoc.LastModified
                
                &#039;рекурсивный поиск в БД Адресаты , если родительский элемент верхнего уровня - скрыт или удален
                mainadrid$=adrdoc.ParentDocumentUNID
                While Not mainadrid$=&quot;&quot;
                    Set mainadrdoc = adrdb.GetDocumentByUNID(mainadrid$)
                    mainadrid$=mainadrdoc.ParentDocumentUNID
                Wend
                
                If Not mainadrdoc Is Nothing Then
                    fla$=mainadrdoc.flag_not_visible(0)&#039; скрыт ли  родительский элемент верхнего уровня
                    del$=CStr(mainadrdoc.delete(0)) &#039; или удален в БД Адресаты
                End If
                doc.flag_not_visible=adrdoc.flag_not_visible
                If fla$=&quot;1&quot; Then doc.flag_not_visible=&quot;1&quot; &#039;скрыть, если родительский элемент верхнего уровня скрыт     
                doc.delete=CStr(adrdoc.delete(0))
                If del$=&quot;1&quot; Then doc.delete=&quot;1&quot; &#039;или удален в ВЭД
                
                doc.Server_name=adrdoc.Server_name &#039; ФИО, или назв орг подведа.
                doc.Server_id=adrdoc.Server_id
                doc.type_adr =adrdoc.type_adr  &#039; в БД адресаты у орг подведа - 1, а у человека - 2. 
                
                stsubdivision$ = doc.Server_id(0)
                &#039;    Print &quot;Server_id &quot; stsubdivision$ 
                sts=stsubdivision$
                
                doc.donorparentid=adrdoc.ParentDocumentUNID
                Set maindoc=view.GetDocumentByKey(doc.donorparentid(0)) &#039; ищем родительский элемент в ВЭД по donorid в виде reforgs3 в ВЭД
                If Not maindoc Is Nothing Then  &#039;вообще всегда есть
                    Print    maindoc.Server_name(0) &quot; /родитель/ &quot; maindoc.type_adr(0)
                    If maindoc.type_adr(0)=&quot;1&quot; Then 
                        &#039;Print &quot;родитель  &quot;  doc.Server_name(0) &quot;  у  &quot;  maindoc.nam(0)
                        sts= maindoc.Server_id(0) + &quot;.&quot; + doc.Server_id(0)
                        If stsubdivision$ &lt;&gt; sts Then 
                            Print &quot;подвед &quot;  doc.Server_name(0) + &quot; // &quot; sts
                            stsubdivision$ = maindoc.Server_id(0)
                        End If
                    End if
                    doc.sts = sts
                    doc.nam=maindoc.nam   &#039; Наименование организации  
                    doc.shnam=maindoc.shnam &#039; краткое Наименование организации  
                    doc.code=maindoc.code   &#039;   Код организации в МЭД
                    doc.xmlstr=&quot;&lt;destination&gt;&lt;legalentity&gt;&lt;kodorgout&gt;&quot;+doc.code(0)+&quot;&lt;/kodorgout&gt;&lt;nameorg&gt;&quot;+doc.nam(0)+&quot;&lt;/nameorg&gt;&lt;structuralsubdivision&gt;&quot; + stsubdivision$ +&quot;&lt;/structuralsubdivision&gt;&lt;post&gt;&quot;+doc.Server_name(0)+&quot;&lt;/post&gt;&lt;/legalentity&gt;&lt;/destination&gt;&quot;        
                    Call doc.MakeResponse(maindoc)        
                End If
                &#039;Print &quot;sts &quot; sts
                
                Call doc.ComputeWithForm(1,0)
                Call doc.Save(1,0)
                
            End If    
l1:    
            Set adrdoc=adrview.GetNextDocument(adrdoc)
        Wend
    Next
    Print &quot;всего &quot; i
    Exit Sub
ErrH:
    Print &quot;Ошибка АДРЕСАТЫ &quot; &amp; Error(Err) &amp; &quot; в строке &quot; &amp; Erl    
    Exit Sub
End Sub</code></pre></div>]]></description>
			<author><![CDATA[null@example.com (admin)]]></author>
			<pubDate>Mon, 24 Oct 2022 13:25:00 +0000</pubDate>
			<guid>https://itpmr.ru/viewtopic.php?pid=124878#p124878</guid>
		</item>
	</channel>
</rss>
