Solving a problem of GetItemValue in Lotus script

Hi, I am new to lotus and currently facing a problem dealing with the code shown as below:

Dim session As NotesSession

Dim db As NotesDatabase

Dim dc As NotesDocumentCollection

Dim doc As NotesDocument

Set session = New NotesSession

Set db = session.CurrentDatabase

Set dc = db.UnprocessedDocuments

Set doc = dc.GetFirstDocument

Dim award As Variant

award = doc.GetItemValue( “AwardHistory” )

Messagebox( award( 0 ) )

This code is copied exactly same from the example in the ‘help’ session, but not the field name only. However, I got an error message with “Object Variable Not Set” with this code. I still couldn’t find out which line of the code brings out the error. Can anyone enlighten me about this ? Thank you in advanced!

Subject: you are assuming that field award exists - maybe it’s not there

so first you must test

If doc.HasItem(“award”) then

Subject: Too many assumptions - clean LotusScript

You posted:

Dim session As NotesSession

Dim db As NotesDatabase

Dim dc As NotesDocumentCollection

Dim doc As NotesDocument

Set session = New NotesSession

Set db = session.CurrentDatabase

Set dc = db.UnprocessedDocuments

Set doc = dc.GetFirstDocument

Dim award As Variant

award = doc.GetItemValue( “AwardHistory” )

Messagebox( award( 0 ) )

You’ll want to do a little error-checking before you use this code, since you 1) might not have a “doc” and 2) might not have an “award” value.

Here’s a “healthier” version of the same code:

Dim session as NotesSession

Dim db as NotesDatabase

Dim dc as NotesDocumentCollection

Dim doc as NotesDocument

Set session = New NotesSession

Set db = session.CurrentDatabase

Set dc = db.UnprocessedDocuments

Set doc = dc.GetFirstDocument

Do Until(doc is nothing)

Messagebox(Join(doc.GetItemValue(“AwardHistory”), “”))

Set doc = dc.GetNextDocument(doc)

Loop

To explain:

  1. This code will run through each NotesDocument in your NotesDocumentCollection. If there IS no initial NotesDocument, it will not run.

  2. Since GetItemValue returns an array of values from the target NotesItem (in this case “AwardHistory”), we’re going to use a Join to combine all values into a single String. I’m assuming of course that AwardHistory only has a single value. If there is no value in this NotesItem or the “AwardHistory” NotesItem doesn’t exist, it will return “”.

Hope this helps!

-Chris

Subject: Debugger

Turn on the lotusscript debugger in the Tools menu to find out which line the error is at

Subject: Debugger detects, but couldn’t solve the problem

Hi,the debugger detects these 2 lines.

Dim session As NotesSession

award = doc.GetItemValue( “AwardHistory” )

But I am still unable to find out any mistake done by these lines. Anyone has any idea?

Subject: Debugger gives information; YOU must solve the problem.

I see your problem.

Some methods and properties in LotusScript are sensitive to the context in which they’re used. You can’t simply take any sample code and paste it in anywhere you like, and assume it will work. Think about the meaning of what you’re doing in the given context.

Read the documentation for the functions you are using, particularly UnprocessedDocuments.

Read Debugging Domino Applications part 1 and part 2 .

In the debugger, pay attention not only to which line generates the error, but also to what happens on previous lines, and the values of variables. Often the mistake that causes an error is an incorrectly assigned variable, but the error message doesn’t occur until you try to use that variable later.

Pay special attention to the Usage section of the method/property descriptions.

Subject: the award field not set value

You should set award field initial value is award.