Posts Tagged ‘notesdocument’

21 Sep 2012
3

LotusScript Tip: Set Readers and Authors Fields in new Documents

Hi Everyone. I’ve been using this forever but I noticed recently that it’s not really common knowledge.

Let’s say you have a Form Design and in it you have a Readers and Authors field. Now let’s also say that you create NotesDocuments for this Form Design in the back-end. The question is: How do you populate a field in LotusScript and turn that field into a READERS or AUTHORS if required.

Many use a famous trick called “ComputeWithForm” which is a method that belongs to the NotesDocument Object. In simple terms, a ComputeWithForm will evaluate the entire NotesDocument against the Form Design it’s associated with….i.e. If you have a Form with 50 Computed Fields that contain various @Formulas, a ComputeWithForm will evaluate each of those Formulas for your NotesDocument Object.

e.g.

‘ VARIABLES
Dim ss as New NotesSession
Dim db as NotesDatabase
Dim doc as NotesDocument
 
‘ CODE
Set db = ss.CurrentDatabase
Set doc = db.CreateDocument
 
Call doc.ReplaceItemValue( “Form”, “FormAliasName” )
Call doc.ComputeWithForm( False )
Call doc.Save( True, True )

 

While this can do the job and save you a lot of coding, a ComputeWithForm can make your code terribly slow depending on how many fields and Computed Values are in the Form and how many documents you plan on computing. I’ve seen a ComputeWithForm take 2 seconds to evaluate 1 NotesDocument. In that time your code could’ve achieved the same goal and a lot more if you wrote your code to not use it. Anyways, moving on.

 

If you didn’t use ComputeWithForm, you would land up having an issue with Readers and Author Fields in your NotesDocument:

e.g.

‘ VARIABLES
Dim ss as New NotesSession
Dim db as NotesDatabase
Dim doc as NotesDocument
 
‘ CODE
Set db = ss.CurrentDatabase
Set doc = db.CreateDocument
 
Call doc.ReplaceItemValue( “Form”, “FormAliasName” )
Call doc.ReplaceItemValue( “CurrentReaders”, “John Jardin/Ukuvuma” )
Call doc.ReplaceItemValue( “CurrentAuthors”, “John Jardin/Ukuvuma” )
Call doc.Save( True, True )

 

If you had to open the DocumentProperties for this Saved NotesDocument and in the Field Properties Tab click on CurrentReaders, you will see it’s a Normal Text Field. This can cause massive issues from an Access point of view.

To solve this problem, we turn to our ever faithful friend…….NotesItem. Using the NotesItem Object, you can set the Field Type in your code. See below Examples 1 and 2:

e.g.

‘ VARIABLES
Dim ss as New NotesSession
Dim db as NotesDatabase
Dim doc as NotesDocument
Dim item as NotesItem
 
‘ CODE
Set db = ss.CurrentDatabase
Set doc = db.CreateDocument
 
Call doc.ReplaceItemValue( “Form”, “FormAliasName” )
 
Example 1
 
Call doc.ReplaceItemValue( “CurrentReaders”, “John Jardin/Ukuvuma” )
Call doc.ReplaceItemValue( “CurrentAuthors”, “John Jardin/Ukuvuma” )
Call doc.ReplaceItemValue( “CreatedBy”, “John Jardin/Ukuvuma” )
 
Set item = doc.GetFirstItem(“CurrentReaders”)
item.Isreaders = True
 
Set item = doc.GetFirstItem(“CurrentAuthors”)
item.Isauthors = True
 
Set item = doc.GetFirstItem(“CreatedBy”)
item.Isnames = True
 
Example 2 – (Preferred Option)
 
Set item = New NotesItem( doc, “CurrentReaders”, “John Jardin/Ukuvuma”, READERS )
Set item = New NotesItem( doc, “CurrentAuthors”, “John Jardin/Ukuvuma”, AUTHORS )
Set item = New NotesItem( doc, “CreatedBy”, “John Jardin/Ukuvuma”, NAMES )
 

Also, so you know, SSJS for XPages also has a NotesItem Object that you can use similar to what we’ve done here. I’m not sure about Example 2 though.

Until next time, happy coding

John.

24 Oct 2011
3

LotusScript Tip: Return Profile Document from another Database

In all my years of Notes Development, this is my first time I had to return a Profile document to the User, where the profile document existed in another database.

The good news is that this is easier than 123:

1. You will use LotusScript

2. Use the GetProfileDocument method in the NotesDatabase Object, and return it to your NotesDocument Object.

3. Use the EditDocument method in the NotesUIWorkspace Object to return the ProfileDocument to the Current User.

Example:

Sub Click(Source As Button)
   ‘ VARIABLES
Dim ss As New NotesSession
Dim ws As New NotesUIWorkspace
Dim condb As NotesDatabase
Dim myprofile As NotesDocument

    ‘ CODE
 Set condb = ss.GetDatabase( “ServerName”, “FilePathAndName” )

    If condb.IsOpen Then
   Set myprofile = condb.GetProfileDocument( “ApplicationPreferences” )
Call ws.EditDocument( True, myprofile )

 Else
Messagebox “Cannot find Database. Please contact IT Support”, 0 + 48, “Operation Failed”
  End

   End If

End Sub

Enjoy :)

24 Oct 2011
0

Lotus Notes Tip: Error Document Has Not Yet Being Saved

   If you’ve ever come across a Lotus Notes Error, where you click on a button in an Open Document which is in Edit Mode, where the Formula behind the button is an @Command( [RunAgent] ; “AgentName” ), and you receive an error “Document Has Not Yet Being Saved“, a most likely solution will be to set the “Target” parameter on the NotesAgent to “None“. Lotus does not like the target been set to “All Selected Documents”.

Unless I’m mistaken, you would not need the Target to be set to anything else in this particular scenario.

Cheers