Common Lotus Notes code

Source: Internet
Author: User
Tags ole


Common codes of Lotus Notes

1. Check whether the current user is the creator of the document. If not, you cannot edit the document.
Sub querymodechange (source as notesuidocument, continue as variant)
Dim session as new notessession
Dim doc as notesdocument
Dim username as new notesname (session. username)
Set doc=source.doc ument
If not (source. editmode) then
If (Doc. Authors (0) = username. canonical) then continue = true
Else msgbox/"you are not the creator of this document and cannot modify it! /", 0,/" document database /"
Continue = false
End if end sub
2. Key domains cannot be empty during exit Detection
Sub click (source as button)
Dim w as new notesuiworkspace
Dim uidoc as notesuidocument
Dim doc as notesdocument
Set uidoc = W. currentdocument
Name1 = uidoc. fieldgettext (/"name /")
If name1 =/"/" then
MessageBox/"name cannot be blank! /", 0,/" Address Book /"
Exit sub
End if
Call uidoc. Save
Call uidoc. Close
End sub
3. Use the private view to display the document to be processed by the current user. Use the following view formula:
Note: Do not select/"Save to local/" when creating a view. Otherwise, debugging is inconvenient.
Select form =/"recipient 1/" & nextapprover = @ name ([CN]; @ v3username)
4. Active controls in notes
After Ole or other common ActiveX controls are added to the document, they are automatically added to the right of the script editing box of the document.
Add various attributes and methods to the class list of notes. The method for declaring this object in script is as follows:
Sub postopen (source as notesuidocument)
Dim w as notesuiworkspace
Dim uidoc as notesuidocument
Dim AA as Variant
Set W = new notesuiworkspace
Set uidoc = W. currentdocument
Set AA = uidoc. GetObject (/"chart/")/'indicates the OLE object declaration. Note that chart is the name you give to the object.
Then you can use AA. ** to call its method and attributes.
End sub
5. The following is the Script Error Trap Code
Sub subname on error goto errcode/'add your program code below
Exit sub errcode: msgbox/"error (/" & CSTR (ERR) &/")->/" & error $ (ERR), 16,/"error
Error message /"
Exit sub
End sub
6. Whether to save
Set a field in the form named saveoption
Add the following formula to the return button to determine whether to save the file after it exits.
Field saveoptions: =/"1/"; save field saveoptions: =/"0/"; Do not save
7. Use the formula to pop up the dialog box and press OK to continue. Cancel the return.
@ If (@ dialogbox (/"form name/"; [autohorzfit]: [autovertfit];/"Form title/");/"/"; @ return (/"
/"))
8. Use the script to pop up the dialog box and press OK to continue. Cancel the return.
Dim w as notesuiworkspace
If not W. dialogbox (/"form name/", true, true, false, true, false, false,/"fill /")
Then Doc. Close/'user click Cancel to exit
Exit sub
End if
9. Delete document statements in the view
@ Command ([editclear]);
@ Command ([viewrefreshfields])
10. check whether it is a weekend.
Dim dT as notesdatetime
Call DT. setnow
If weekday (Dt. lslocaltime) = 7
Then/'is Saturday,
DT. adjustday (2)/'plus two days to Monday
Elseif weekday (Dt. lslocaltime) = 1
Then/'add one day on Sunday'
DT. adjustday (1)
End if
11. Obtain the current server and path.
Formula: resideserver :=@ subset (@ dbname; 1 );
Currentpath: = @ subset (@ dbname;-1 );
Dironly: = @ if (@ contains (currentpath ;/"/////");
@ Leftback (currentpath;/"//") + /"/////";/"/");
Dbfile: = dironly +/"***. nsf /";
12. Get the current user name.
Formula name ([CN]; @ v3username)
Scriptim s as notessession
Dim myname as newnotesname (S. username)
MessageBox myname. Common
13. Get the formula for the current date:
@ Today @ date (@ created)
Scriptim dT as notesdatetime
Set dt = new notesdatetime (/"/")
Call DT. setnow
14. Common global object Declaration/'----- object variable -----
Dim w as notesuiworkspace
Dim s as notessession
Dim dB as notesdatabase
Dim view as notesview
Dim uidoc as notesuidocument
Dim doc as notesdocument
Dim item as notesitem
Dim dT as notesdatetime
Dim username as notesname
15. Some calculation fields do not have a value at the beginning. If you do not give it a value, an error is returned. The following formula assigns a value to the calculation field.
@ If (bfield =/"/"; 0; bfield)
16. special characters
@ Char (13) the CHR (13) function is used in the press ENTER script in the @ prompt box)
17. How can I determine if there is no document in the view?
 
Set Doc = VW. getfirstdocument ()
If Doc is nothing then
.....

End if

18. How do I put the query results in a folder?
 
Put the search result in a folder named newfolder and jump to the folder.
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
 
How do I delete all private views in the database?
 
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)
/'This local view is processed as a document to get some attributes of the view.
Viewflag = Doc. getitemvalue (/"$ flags /")
If viewflag (0) =/"pyv/" then
In/'view attributes, $ flags is/"pyv/", which is a private view.
Call I. Remove
End if
End forall
 
In notes, how does one call the process in the ODBC data source?
 
The following is a script code that uses ODBC to call the ACCESS database (database ).
 
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 (/"database /")
Qry. SQL =/"select * from database /"
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
 
Refresh the current document from the background?
 
Close the current document before opening it.
Set doc=uidoc.doc ument
......
Call uidoc. Save ()
Call uidoc. Close ()
Set uidoc = ws. editdocument (DOC)

Obtain the selected document in the current view?
 
You can use the unprocesseddocuments attribute of notesdatabase.

Dim session as new notessession
Dim dB as notesdatabase
Dim collection as notesdocumentcollection
  
Set DB = session. currentdatabase
Set collection = dB. unprocesseddocuments

Unprocesseddocuments is actually very useful
 
Exchange data in notes and 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 =/"name /"
Excelsheet. cells (1, 2). value =/"age /"
   
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 content /")
Excelapplication. Quit
Set excelapplication = nothing
   
How can I view all documents?
 
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
 
How to call a formula in scipt

For example, if you want to get the common name of the server name, use @ name () in the script. Assume that the server variable obtains the server name.
 
Run the formula with evaluate in script, such as servername = evaluate (/"@ name ([CN]; server )/")
 

How to Use the script proxy to get CGI variables

Dim session as new notessession
Dim doc as notesdocument
Set Doc = session. documentcontext
MessageBox/"user =/" + Doc. remote_user (0)
 
How can I use WIN32API to hide a menu?
 
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

How to determine whether an RTF is null
 
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 1, 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

 

How to return a data type
 
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)

 

How to determine whether a file directory exists

If dir $ (dirname, attr_directory) = /"/"
Then/'Directory does not exist
Else
/'Directory does exist
End if
 
How to run proxy in Lotus script

Set S = Createobject (/"notes. notessession /")
Set DB = S. getdatabase (/"/",/"DB. nsf /")
Set a = dB. getAgent (/"someagent /")
Call S. setenvironmentvar (/"agentdocid/",/"ABCD /")
Call a. Run
 
How to obtain the file path of the current database
 
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
 
How to compare two date fields

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
 
@ Mailsend in script
 
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

How to Use LotusScript to start attachments
 
First, use the embeddedobjects class to remove the attachment to a temporary folder, and then run it using shell command statements.

How to Create a name domain, reader domain, and author domain in Lotus script

Create a/"specialtype/" Name field
Dim variablename as new notesitem (notesdocument, name $, value [, specialtype %])
Create a/"author/" author domain
Dim tauthor as new notesitem (Doc,/"author/", auths, authors)
Tauthor. issummary = true
 

How to automatically modify the reply document after modifying the master document
 
Sub querysave (source as notesuidocument, continue as variant)
Dim collection as notesdocumentcollection
Dim doc as notesdocument
Dim form, parentstatus, status as string
Set Doc = source. Document
Set collection = Doc. Responses
Set Doc = collection. getfirstdocument
Parentstatus = source. fieldgettext (/"status /")
While not (Doc is nothing)
Form = Doc. getitemvalue (/"form/") (0)
Status = Doc. getitemvalue (/"status/") (0)
If (form =/"task/") and (status <> parentstatus) then
Call Doc. replaceitemvalue (/"status/", parentstatus)
Call Doc. Save (true, false)
End if
Set Doc = collection. getnextdocument (DOC)
Wendend
Sub
 
How to get the server time in time
 
Dim doc as notesdocument
Set Doc = serverdb. createdocument
Createdate = Doc. Created
............
Do not save this document

In Lotus scripts, how does one add a carriage return to the string?

/"Aaa/" + CHR (10) +/"BBB /"
 

How to block users from deleting objects with the delete key
 
Use the following statement in querydocumentdelete of the database script.
Continue = false posting: http://bbs.chinalotus.com/attachment.php? Aid = 2887.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.