LotusScript 是完全物件導向的程式設計語言。它通過預定義的類與 Domino 介面。Domino 監控使用者代碼的編譯和載入,並且自動包含 Domino 的類定義。 訪問現有的對象最好使用 LotusScript,例如:根據其他文檔的值來更改一個文檔中的值。LotusScript 提供了一些公式沒有的功能,例如:操作資料庫存取控制列表 (ACL) 的能力。 寫script關鍵是取對象,查看對象的屬性,所以你要學會看notes提供的Script協助。下面是我收集的一些script例子。一般是比較技巧的程式。 怎樣判斷視圖中沒有文檔? set doc = vw.getfirstdocument() if doc is nothing then ..... end if 如何將查詢結果放到一個檔案夾裡? 下面是將搜尋結果放到名叫newfolder的檔案夾中,並跳轉到該檔案夾上 Sub Click(Source As Button) Dim docs As notesdocumentcollection Dim doc As notesdocument ........... q=doc.query(0) Set docs = db.ftsearch(q, 0) Call docs.PutAllInFolder( \"newfolder\" ) Call w.OpenDatabase( \"\",\"\",\"newfolder\") End Sub 如何刪掉資料庫中所有私人視圖? Dim session As New notessession Dim db As notesdatabase Dim doc As notesdocument Set db=session.currentdatabase Forall i In db.views Set doc=db.getDocumentByUNID(v.universalID) \' 這個地方視圖當作文檔來處理,以便取到視圖的一些屬性。 viewflag=doc.getItemvalue(\"$flags\") If viewflag(0)=\"pYV\" Then \' 視圖屬性中$flags為\"pYV\"的是私人視圖。 Call i.remove End If End Forall 如何在Notes中調用ODBC資料來源中的進程? 下面是一個利用ODBC調用access資料庫(資料庫)的script代碼 Dim session As New NotesSession Dim con As New ODBCConnection Dim qry As New ODBCQuery Dim result As New ODBCResultSet Set qry.Connection = con Set result.Query = qry con.ConnectTo(\"資料庫\") qry.SQL = \"SELECT * FROM 資料庫\" result.Execute If result.IsResultSetAvailable Then Do result.NextRow id=result.GetValue(\"ID\",id) Loop Until result.IsEndOfData result.Close(DB_CLOSE) Else Messagebox \"Cannot get result set for AssetData\" Exit Sub End If con.Disconnect End Sub 獲得當前視圖中選擇了的文檔? 可以用 Notesdatabase 的 Unprocesseddocuments 屬性。 Dim session As New notessession Dim db As notesdatabase Dim collection As notesdocumentcollection Set db = session.currentdatabase Set collection = db.UnprocessedDocuments Unprocesseddocuments 其實很有用的 notes和Excel交換資料 Dim session As New NotesSession Dim db As NotesDatabase Dim view As NotesView Dim doc As NotesDocument Dim excelApplication As Variant Dim excelWorkbook As Variant Dim excelSheet As Variant Dim i As Integer Set excelApplication = CreateObject(\"Excel.Application\") excelApplication.Visible = True Set excelWorkbook = excelApplication.Workbooks.Add Set excelSheet = excelWorkbook.Worksheets(\"Sheet1\") excelSheet.Cells(1,1).Value = \"姓名\" excelSheet.Cells(1,2).Value = \"年齡\" i = 1 Set db = session.CurrentDatabase Set view = db.GetView(\"abc\") Set doc = view.GetFirstDocument While Not(doc Is Nothing) i = i + 1 excelSheet.Cells(i,1).Value = doc.ClassCategories(0) excelSheet.Cells(i,2).Value = doc.Subject(0) Set doc = view.GetNextDocument(doc) Wend excelSheet.Columns(\"A:B\").Select excelSheet.Columns(\"A:B\").EntireColumn.AutoFit excelWorkbook.SaveAs(\"Script 內容\") excelApplication.Quit Set excelApplication = Nothing 從後台重新整理當前文檔? 將當前文檔先關閉後再開啟 set doc=uidoc.document ...... call uidoc.save() call uidoc.close() set uidoc=ws.editdocument(doc) 在視圖中怎樣曆遍所有的文檔? Dim db As New NotesDatabase( \"Ankara\", \"current\\projects.nsf\" ) Dim view As NotesView Dim doc As NotesDocument Set view = db.GetView( \"Open\\By Due Date\" ) Set doc = view.GetFirstDocument While Not ( doc Is Nothing ) .................... Set doc = view.GetNextDocument( doc ) Wend 在scipt中如何調用公式 例如我們想要取伺服器名的普通名,在script中用@name() ,假設server變數以取到伺服器名稱 在script中用Evaluate可以運行公式,如:servername=Evaluate(\"@name([CN];server)\") 怎樣用script代理取到CGI變數 Dim session As New NotesSession Dim doc As NotesDocument Set doc = session.DocumentContext Messagebox \"User = \" + doc.Remote_User(0) 如何使用Win32API隱藏菜單呢? 1. Declarations : Declare Function GetActiveWindow Lib \"user32.dll\" () As Long Declare Function SetMenu Lib \"user32.dll\" ( Byval hmenu As Long, Byval newmenu As Long ) As Integer 2. Sub HiddenMenu() Dim hwnd As Long hwnd = GetActiveWindow() Call SetMenu(hwnd,0) End Sub 怎樣判斷一個RTF為空白值 Function IsRTFNull(rtfield As String) As Integer On Error Goto Errhandle Dim workspace As New NotesUIWorkspace Dim uidoc As NotesUIDocument Set uidoc = workspace.CurrentDocument currentfield = uidoc.CurrentField Call uidoc.GotoField(rtfield) Call uidoc.SelectAll Call uidoc.DeselectAll If currentfield <> \"\" Then Call uidoc.GotoField(currentfield) End If IsRTFNull = False Exit Function Errhandle: Select Case Err Case 4407 \'the DeselectAll line generated an error message, indicating that the rich text field does not contain anything If currentfield <> \"\" Then Call uidoc.GotoField(currentfield) End If IsRTFNull = True Exit Function Case Else \'For any other error, force the same error to cause LotusScript to do the error handling Error Err End Select End Function 怎樣返回一個資料的類型 Declarations Class ReturnObj Private m_stName As String Private m_stType As String Property Get NameVal As String NameVal = m_stName$ End Property Property Get TypeVal As String TypeVal = m_stType$ End Property Sub new( arg_stName$, arg_stType$ ) m_stName = arg_stName$ m_stType = arg_stType End Sub End Class Function Test() As ReturnObj Set Test = New ReturnObj( \"Name\", \"Type\" ) End Function Initialize Dim var Set var = Test() Msgbox( var.NameVal ) 怎樣判斷一個檔案目錄是否存在 If Dir$(dirName, ATTR_DIRECTORY) = \"\" Then \'Directory does not exist Else \'Directory does exist End If 怎樣在lotusScript中運行代理 Set s = CreateObject(\"Notes.NotesSession\") Set db = s.GETDATABASE(\"\", \"db.nsf\") Set a = db.GETAGENT(\"SomeAgent\") Call s.SETENVIRONMENTVAR(\"AgentDocID\", \"ABCD\") Call a.RUN 怎樣才能得到當前資料庫的檔案路徑 Public Function GetDatabasePath( db As Notesdatabase ) As String Dim position As Integer position = Instr( db.FilePath, db.FileName ) GetDatabasePath = Left( db.FilePath , position - 1 ) End Function 怎樣比較兩個日期型的域 mdate1V = document.DateField1(0) mdate2V = document.DateField2(0) If mdate1V < mdate2V Then MsgBox \"DATE 1 LESS THEN DATE 2\" Else MsgBox \"DATE 2 LESS THEN OR EQUAL TO DATE 1\" End If 在Script中做到@mailsend Function SendMailMemo(sendTo As String, _ cc As String, _ bcc As String, _ subject As String, _ body As String, _ linkTo As NotesDocument) As Integer On Error Goto ErrorHandler Dim mailDb As New NotesDatabase(\"\", \"\") Dim mailDoc As NotesDocument Dim rtItem As NotesRichTextItem Call mailDb.OpenMail If (mailDb.IsOpen = False) Then Call mailDb.Open(\"\", \"\") Set mailDoc = mailDb.CreateDocument mailDoc.Form = \"Memo\" mailDoc.SendTo = sendTo mailDoc.CC = cc mailDoc.BCC = bcc mailDoc.Subject = subject Set rtItem = mailDoc.CreateRichTextItem(\"Body\") Call rtItem.AppendText(body) If Not(linkTo Is Nothing) Then Call rtItem.AddNewLine(2) Call rtItem.AppendDocLink(linkTo, \"Double-click to open document\") End If Call mailDoc.Send(False) SendMailMemo = True Exit Function ErrorHandler: Print \"Error \" & Str$(Err) & \": \" & Error$ Resume TheEnd TheEnd: SendMailMemo = False End Function 怎樣用lotusScript啟動附件 首先使用EmbeddedObjects類將附件拆離到一個臨時檔案夾裡,然後用shell命令語句運行它 怎樣在lotusScript中建立一個姓名域、讀者域、作者域 建立一個\"specialType\"姓名域 Dim variableName As New NotesItem( notesDocument, name$, value [,specialType%]) 建立一個\"Author\"作者域 Dim TAuthor As New NotesItem(doc, \"Author\", Auths, AUTHORS) TAuthor.IsSummary = True |