Archives for September, 2012

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.

18 Sep 2012
3

TUTORIAL: Integrating XPages with DB2 – Part 2

Hi everyone. So, just 2 things firstly:

1. This is an extended Post to David Leedy’s NotesIn9 Posting of “Intro to XPages and Relational Data – Part 2“.

2. I do apologize that this took a while to publish. This is one of the more challenging years to find some free time to contribute to the Domino and XPages community. Having said that, I have quite a few Video Tutorials planned before this year ends, so stay tuned :)

 

Now that that’s out the way…..this post is Part 2 to the “Integrating XPages with DB2 – Part 1“. In this Video I show you how to Create/Read/Update/Delete DB2 Data using XPages. More importantly, I show you how to empower the User to perform all these functions via a User Interface. It’s usually easy to write this logic in the back-end, but a little more involved when handing that power over to the User.

 

The good news is that it’s fairly straightforward. I show you some quick functions that will get you up and running in no time. As I explained in the Video though, there are much more advanced ways of integrating to DB2. This will involve some knowledge of DB2 itself. The keyword is…..”Stored Procedures“. This is where the power lies. A Stored Procedure is very much like a Sub Routine in LotusScript or a Function in Java or JavaScript, but you code in SQL Language. You can pass the Stored Procedure parameters, have all your logic neatly set out in a central place in DB2 and return values from the Stored Procedure which will allow you do things like create Child Documents, etc.

Later on in the near future, I will think up a straightforward Tutorial which will show you how this all works.

I hope you enjoy this Video. I really enjoyed making it. It was one of my smoothest recordings where everything went right the first time.

I want to thank David Leedy as always for adding this to his NotesIn9 Series. You da man :)

Cheers.

John

 

IMPORTANT NOTE: If you are not able to view this Video in HD, please Click Here to open this video up in a different Player.