|
Di seguito la traduzione di un articolo che illustra come gestire tramite LotusScript gli allegati in un campo rich-text sul documento Lotus Notes aperto sul front-end.
 Aggiornare dinamicamente campi rich-text con LotusScript Titolo originale: "Dynamically update Lotus Notes rich-text fields using LotusScript" Autore: Amith Narera 11.20.2007 
Una modifica effettuata su un documento Lotus Notes nel back-end viene solitamente riprodotta nel documento di front-end, ma u'eccezione a questo comportamento sono i campi di tipo rich-text. Per le modifiche ai campi rich-text, si deve chiudere il doumento Lotus Notes di front-end e aprirlo di nuovo usando il metodo NotesUIWorkspace.EditDocument. Comunque, questo fa "scatenare" tutti gli eventi associati alla form Lotus Notes. Questo tip aggira questo problema consentendo di aggiornare dinamicamente i campi rich-text del front-end senza chiudere e riaprire la form Lotus Notes principale. A scopo esemplificativo, aggiungo l'attuale username Lotus Notes, l'ora di sistema e gli allegati (selezionati dall'utente Lotus Notes) al campo rich-text. Il seguente codice LotusScript consente anche di appendere item rich-text da un altro documento Lotus Notes (codice commentato). Quello che segue è uno schema di come il codice LotusScript lavora: - Crea un documento Lotus Notes "di appoggio" nel back end usando il metodo db.CreateDocument.
- Aggiunge un campo rich-text al documento.
- Esegue tutte le azioni necessarie su questo campo rich-text .
- Apre il documento Lotus Notes nel front-end coun una form "di appoggio" che contine solamente un campo rich-text (con lo stesso nome di quello creato nel secondo passaggio visto prima).
- posiziona il cursore in questo campo rich-text, seleziona tutto il testo, e copia tutto negli appunti.
- Chiude la form Lotus Notes "di appoggio".
- Va sul campo rich-text di destinazine sulla form Lotus Notes principale.
- Incolla tutto dagli appunti.
- Missione eseguita.
Questi sono gli step necessari per ottenere il risultato desiderato: - Create a new form. Name it "Dummy Form."
- Place a rich-text field, named "DummyRT" on it.
- Open your main Lotus Notes form where you'd like these updates to happen.
- Create a new Action button, and name it "Update RT Field." You may use the LotusScript code anywhere. For the sake of simplicity I am using it in a button.
- Select LotusScript as the coding language and paste the code given below into it.
Sub Click(Source As Button) Dim workspace As New NotesUIWorkspace Dim session As New NotesSession
'COMMENT #######> UiDoc represents the currently open Fron End document, where the rich text field exists. Dim uidoc As NotesUIDocument
'COMMENT #######> Dummy UIDoc ---needed by the code Dim DummyUIDoc As NotesUIDocument Dim db As NotesDatabase
'COMMENT #######> Back End version of DummyUIDoc Dim DummyDoc As NotesDocument
'COMMENT #######> RT Item in DummyDoc ---From where you would be pulling the changes Dim DummyRT As NotesRichTextItem Dim FilePath As Variant Set db = session.CurrentDatabase Set uidoc = workspace.CurrentDocument Set DummyDoc = db.CreateDocument 'COMMENT #######> Set Fields for Dummy Document DummyDoc.Form = "Dummy Form" ' NOTE: It shud be dummy form, not your main form. DummyDoc.SaveOptions = "0" 'COMMENT #######> Get the File path for the file to be attached FilePath = workspace.OpenFileDialog(True, "Select Files") 'COMMENT #######> Insert RT Field Set DummyRT = New NotesRichTextItem(DummyDoc,"DummyRT") 'COMMENT #######> Update the Field- as per your requirements Call DummyRT.AppendText(session.CommonUserName & " - ") Call DummyRT.AppendText(Cstr(Now)) Call DummyRT.AddNewline(1) 'COMMENT #######>Embed Selected Files, if Any If Not Isempty(FilePath) Then Forall CurrentFilepath In FilePath Call DummyRT.EmbedObject(1454,"", CurrentFilePath) End Forall End If 'COMMENT #######>You may also append an RT Item from any other document. eg. %REM Dim RTItemB As NotesRichTextItem Set RTItemB = DocB.GetFirstItem("RTItemName") Call DummyRT.AppendRTItem(RTItemB) %END REM 'COMMENT #######> Call this to commit all the RT Item Changes to the Document Call DummyRT.Update 'Here is the Trick '******************************************************************************************* Set DummyUIDoc = workspace.EditDocument(True,DummyDoc) Call DummyUIDoc.GotoField("DummyRT") Call DummyUIDoc.SelectAll Call DummyUIDoc.Copy Call DummyUIDoc.Close(True) 'COMMENT #######> Goto Main doc Rich Text Field (desitnation field) Call uidoc.GotoField("RTF") Call uidoc.Paste
'******************************************************************************************* Messagebox "Process Completed Successfully.", 64, "Complete" End Sub
Now -- with a click of this action button -- you can update the front end of your rich-text item in real-time without having to close and re-open the main Lotus Notes document. You can also apply the same logic to move contents of one rich-text item to the other rich-text item on the same form in real time -- without having to re-open the front end document. If you'd like to do that, this code will help you: Call UIDoc.GotoField("FirstRT") Call UIDoc.SelectAll Call UIDoc.Copy Call uidoc.GotoField("SecondRT") Call uidoc.Paste
Riporta quest'articolo sul tuo sito! | Visualizzazioni: 261
Powered by AkoComment Tweaked Special Edition v.1.4.6 AkoComment © Copyright 2004 by Arthur Konze - www.mamboportal.com All right reserved |