GetAllDocumentsByKey - Object Variable not set Error

I am trying the following to get all the documents in my ViewCatogory with First “Catogorised sorted” column

myKey = uidoc.FieldGetText(“DocNum”)

Set dc = view.GetAllDocumentsByKey(myKey, False)

getting an error - Object Variable not set

What could be the reason?

thanks in advance

Subject: GetAllDocumentsByKey - Object Variable not set Error

Hello,

i think your key contains number vlaue. convert them into Cstr(myfield)

or could you please post your code once again.

thanks

Dev

Subject: RE: GetAllDocumentsByKey - Object Variable not set Error

  • Object Variable Not Set - This is the most common error you could get. It simply means the variable you’ve used to get the object ref. of any class has not be set/instantiated.

  • It is suggested incorporate the error handler, drill down to the line number/line of code generating this error.

  • Once you identify the line of code, use the above info to check if any object in that line of code has not been initialized.

As per you current input you could get this error either if “uidoc” has not been set properly or “view” object has not been initialized.

Thanks

Dev"

Subject: GetAllDocumentsByKey - Object Variable not set Error

Try using the LotusScript debugger in the Notes client then run the code again and the debugger will tell you what line it’s erroring on, from there you can see what objects have a value and what don’t.

Just make sure you dim and set everything correctly.

For example:

Dim workspace as new notesuiworkspace

Dim uidoc as notesuidocument

Dim view as notesview

Dim mkey as string

set uidoc = workspace.currentdocument '(assuming that the uidoc is indeed the one you currently have open)

'how are you setting the view? I would normally set the view by doing:

dim sess as new notessession

dim db as notesdatabase

set db = sess.currentdatabase

set view = db.getview(viewname)

Subject: RE: GetAllDocumentsByKey - Object Variable not set Error

here is my code …in debugger it gives erro on Set dc = view.GetAllDocumentsByKey(myKey, True)

Should my view have first sorted column as Categorised column also?

I am writing an agent that get triggered when ever a user saves a document. It gets all the documents from a view and stamps them Not latest except my current document ??


Dim workspace As New NotesUIWorkspace

Dim uidoc As NotesUIDocument

Dim myKey As String

Dim myRefNum As String

Dim DocRefNum As String



Dim session As New NotesSession

Dim db As New NotesDatabase( "Servername", "mydb.nsf" )

Dim view As NotesView	

Dim doc As NotesDocument

Dim item As NotesItem

Dim dc As NotesDocumentCollection



Set view = db.GetView("(AllCATUpdateLookup)")



Set uidoc = workspace.CurrentDocument

myKey = uidoc.FieldGetText("DocNum")

myRefNum = uidoc.FieldGetText("RefNum")



Set dc = view.GetAllDocumentsByKey(myKey, True)	



Set doc = dc.GetFirstDocument

While Not doc Is Nothing	

	

	DocRefNum = doc.GetItemValue( "DocRefNumber" )

	If (DocRefNum <>myRefNum) Then		

		Set item = doc.ReplaceItemValue( "Latest", "No" )

		Call doc.Save( False, True )	

	Else			

		Continue = ture		

	End If	

	Set doc = dc.GetNextDocument(doc)		

Wend

Subject: RE: GetAllDocumentsByKey - Object Variable not set Error

When you run the script through the debugger is the view object set to anything? If the error is occurring at the line you specify, it sounds like your NotesView object is not being set.

Other possible culprits–if the (AllCATUpdateLookup) view doesn’t have a sorted column, GetAllDocumentsByKey will fail. Your key has to correspond to the first sorted column.

I would also check in the debugger to see if the NotesDatabase object is open when you instantiate it. If it is not, you will not be able to set the view object, which would cause your issue as well.

hth.

brandt

Subject: RE: GetAllDocumentsByKey - Object Variable not set Error

I chekced it fails on that line…

My view already has the first sorted column can you pl suggest another alternative

I am trying a simple thing…

I am saving a document. on the save event I want to stamp

all the document as “Not Latest” In my view with first sorted column as my “Key” whare the RefNum is not same as myUI doc refnum.

sample code would help. thanks

Subject: RE: GetAllDocumentsByKey - Object Variable not set Error

Your problem has nothing to do with the design of the view. You aren’t getting far enough to have a problem with the view design because you aren’t finding the view at all.

Your problem is not on the line: Set dc = view.GetAllDocumentsByKey(myKey, True)

That’s just where the error occurs. The error occurs because view has the value Nothing. That should not be the case. To find the problem, you have to look for the line where view is assigned:

Set view = db.GetView(“(AllCATUpdateLookup)”)

Apparently the view name here is incorrect, or you do not have access to the view, or db points to the wrong database. For some reason the view is not being found.

Subject: RE: GetAllDocumentsByKey - Object Variable not set Error

Andre, wouldn’t the GetView fail if there was a problem in

Dim db As New NotesDatabase( “Servername”, “mydb.nsf” )

and the db object wasn’t properly instantiated?. Perhaps it failed due to an invalid server name or db name.

Subject: RE: GetAllDocumentsByKey - Object Variable not set Error

In that case, I would expect an error on the Set view = line (Database has not been opened yet) instead of it just returning Nothing.

Subject: RE: GetAllDocumentsByKey - Object Variable not set Error

You did not answer some of my other questions–

is the view object being set or is it nothing? you can check this through the debugger.

is the database object open? if it isn’t, you will not be able to set the view object, and you will get this error. This too can be checked through the debugger.

On the surface your script looks like it SHOULD work, but without those answers, we can’t help you.

brandt

Subject: RE: GetAllDocumentsByKey - Object Variable not set Error

can I get your email id I willfwd you my Dbugr print screen. thanks

Subject: RE: GetAllDocumentsByKey - Object Variable not set Error

No offense, but if you can’t look in the debugger and tell me if an object is actually set to something by looking at it, you are either in desperate need of training on LS or you’re in the wrong line of work…

brandt