Object variable not set

I am trying to change the field value with lotusscript and get object variable not set?

dim s as notessession

dim db as notesdatabase

dim doc as notesdocument

set s = new notessession

set db = s.currentdatabase

doc.newfield = “2”

Subject: Object variable not set

Kathy,

You never set “doc”. If you look at your code in the LotusScript Debugger, you will see that the doc variable has no value.

Ken

Subject: Object variable not set

you do not have a document selected.

if your agent is running on the selected documents you need to add the following…

dim dc as notesDocumentCollection

after your set dB put in

set dc = dB.unprocessedDocuments

set doc = dc.getfirstDocument

while not ( doc is nothing)

doc.newfield = “2”

call doc.save( true, true)

set doc = dc.getnextDocument( doc)

wend

I think i got the syntax right.

john

Subject: RE: Object variable not set

what if you only want to run the agent on the highlighted docuement? Do i still have to use the method getfirstdocument

Subject: RE: Object variable not set

yes.

the code works even if you had one or more documents. if you had just one, then when the code try to get the next document it will return nothing - and break the while.

John

Note: the agent must be set to run on selected documents.

Subject: RE: Object variable not set

how would you write it if you were going to run it from the action menu?

thanks

Subject: RE: Object variable not set

i take it the action is in a view. I would leave the agent just as it is, and then in the action you could either run a simple action and select run an agent, then select the agent name. the same could be done by using formula language.

@command( [toolsrunmacro];“the agent name”)

i would use the latter. in either case, you can also go back to your agent and make it more veristile.

John

Subject: RE: Object variable not set

If you absolutely want only the currently highlighted document (as opposed to all selected documents), then use the UI view and CaretNoteID to get the NoteID of the highlighted document, and db.GetDocumentByID to get the document object (DocumentContext can also work, but that usage is superceded by CaretNoteID). In either case, you have to set the document object; Notes won’t do it for you in LotusScript.