Sub CreateOutputDoc
On Error Goto EH
'=dims
Dim Server As String
Dim db As NotesDatabase
Dim view As NotesView
Dim doc As NotesDocument
Dim nm As NotesName
Dim directory As String
Dim Files As Variant
Dim itm As NotesRichTextItem
Dim fp As String
Dim uidoc As NotesUIDocument
Dim udoc As NotesDocument
'=get db
Server = Lcase(Trim(Cstr(ini.doc.DocServer(0))))
Set db = ini.s.GetDatabase(Server, "B.nsf", False)
If db Is Nothing Then Error 1984, "БД «Исходящие документы» не доступна!"
'=check Output doc if already created
Set view = db.GetView("(DocRequestUNID)")
view.AutoUpdate = False
Call view.Refresh
Set doc = view.GetDocumentByKey(ini.doc.DocRequestUNID(0), True)
If Not doc Is Nothing Then Error 1984, "Исходящий документ уже создан!"
'=set environment vars
Call ini.s.SetEnvironmentVar("OutputdocFilesForAttachments", "")
Set nm = New NotesName(ini.s.UserName)
directory = ini.GetTempDir + nm.Common
If Dir$(directory, 16) = "" Then Mkdir directory
Files = Split("", "")
Set itm = ini.doc.GetFirstItem("F_Attach")
If Not itm Is Nothing Then
Forall obj In itm.EmbeddedObjects
If Not obj Is Nothing Then
If obj.Type = EMBED_ATTACHMENT Then
fp = directory + "\" + obj.Source
Call obj.ExtractFile(fp)
Files = Arrayappend(Files, Replace(fp, "\", "\\"))
End If
End If
End Forall
End If
Files = Arrayunique(Fulltrim(Files), 5)
If Trim(Join(Files, "")) <> "" Then Call ini.s.SetEnvironmentVar("OutputdocFilesForAttachments", Join(Files, "|"))
'=compose new Output doc
Set uidoc = ini.w.ComposeDocument(db.Server, db.FilePath, "output1")
Set doc = uidoc.Document
'=patch fields
doc.DocRequestUNID = ini.doc.DocRequestUNID(0)
doc.ReqType = "Служебная записка"
doc.Subject = "Справка"
doc.category = "Не задана"
doc.orgsorepid = "$"
doc.s = "$"
doc.recepient = ini.doc.F_Client_Name(0)
doc.rf = "Частное лицо"
doc.to = "Частное лицо"
doc.recepient_1 = doc.to(0) + "->" + doc.recepient(0)
'=attaching files in query recalc on Output doc
Call uidoc.RefreshHideFormulas
Call uidoc.Refresh(True)
'=delete handles
Set doc = Nothing
Set uidoc = Nothing
Call ini.s.SetEnvironmentVar("OutputdocFilesForAttachments", "")
If Trim(Join(Files, "")) <> "" Then
Forall File In Files
Kill Replace(File, "\\", "\")
End Forall
End If
Exit Sub
EH:
Call ini.s.SetEnvironmentVar("OutputdocFilesForAttachments", "")
If Err = 1984 Then
Messagebox Error$, 16, "Ошибка"
Elseif Err = 4412 Then
Print Cstr(Err) + " (" + Cstr(Erl) + ") " + Error$
Else
Messagebox Cstr(Err) + " (" + Cstr(Erl) + ") " + Error$, 16, "Ошибка"
End If
Exit Sub
End Sub