WebQuerySave Agent Error : Object variable not set

hi all

Im trying to get two webfield values using javascript and lotus script.

the scenario is :

i have two fields namely

1.Answers

2.Docids

the two fields above said are dynamically generated through HTML tags by another agent.

now i ave same two fields namely Answers and Docids in the webform and when submitting the webform with values entered in those HTML fields i can get the same values in teh Notes field’s

this can be accomplished by a WQS agent using Session.DocumentContext property

now what iam exactly doing is getting the document ids from the Docids HTML field and using the WQS agent getting a handle to the document which is residing in another Database say DB1.

and iam getting a column value from the document and matching the same with the Answers HTML field.

the point is to perform a equality test between the choice got from the Answers HTML field and the original Answer from the document in DB1.

whenever i try to do this iam getting an “Object variable not set” error at the last document.

Anybody can help me please. its very urgent.

iam attaching the WQS Agent code hereby.

Sub Initialize

Dim db As NotesDatabase

Dim db1 As NotesDatabase

Dim doc As NotesDocument

Dim doc1 As NotesDocument

Dim doc2 As NotesDocument

Dim vw As NotesView

Dim webans As Variant,webdocid As Variant,x As Variant,y As Variant,correctans As Variant,userans As Variant,correct As Variant,wrong As Variant,totalscore As Variant

Dim ansstring As Variant,docidstring As Variant,docidcount As Variant,anscount As Variant,temp1 As Variant ,var3 As Variant,var4 As Variant

Dim temp As Variant,var1 As Variant,var2 As Variant,delim As String,last As String,final As String,sepr As String,id As Variant

Dim item As NotesRichTextItem

Dim ss As New NotesSession

Set db=ss.CurrentDatabase

Set doc=ss.DocumentContext

Set db1=ss.GetDatabase("Training","OnlineRecruitment\Testingphase2.nsf","")

Msgbox "DB 1 ok"

Set vw=db1.GetView("vwunids")

Msgbox "view ok"

Set doc1=db.CreateDocument

Set doc2=db.CreateDocument

webans=doc.GetItemValue("Answers")(0)

webdocid=doc.GetItemValue("Docids")(0)

Msgbox " web fields ok"

Msgbox webans

Msgbox webdocid

’ performing splitting operation for both userchosen answer and document id’s

Msgbox" removing the ; from the string containment for document id's "



temp=webdocid

var1=Len(temp)

var2=(var1-1)

last=Left(temp,var2)



Msgbox " performing split operation for document id's"



delim=";"

docidstring=Split(last,delim)

docidcount=Ubound(docidstring)



Msgbox " removing the ; from the string containment for userchosen answers"



temp1=webans

var3=Len(temp1)

var4=(var3-1)

final=Left(temp1,var4)



Msgbox " performing split operation for userchosen answer's"



sepr=";"

ansstring=Split(final,sepr)

anscount=Ubound(ansstring)



Msgbox " initialise correct and wrong score	"

correct=0

wrong=0

y=0

Msgbox docidcount

Msgbox anscount

Msgbox " looping through the document id's to get the correct answer from DB1 for the question given."

Forall docid In docidstring

	id=docid

	Msgbox id

	Set doc2=vw.GetDocumentByKey(id,True)

	correctans=doc2.GetItemValue("origans")(0)

	Msgbox "correct answer is : "&correctans

	userans=ansstring(y)	

	Msgbox "user chosen answer is : "&userans

	Msgbox " answer comparison and score computation"

	

	If(correctans=userans) Then

		correct=correct+1

		Msgbox correct

	Else

		wrong=wrong+0.25

		Msgbox wrong

	End If	

	y=y+1

End Forall



Msgbox "exiting for loop"



totalscore=(correct-wrong)

Msgbox "correct score is : " & correct

Msgbox "Wrong score is : " & wrong

Msgbox "Your total score is : " & totalscore





Msgbox "saving document"

doc1.form="frmresult"

doc1.fldcorrect=correct

doc1.fldwrong=wrong

doc1.fldtotalscore=totalscore

Call doc1.Save(True,False)

Print "WQS done !"

End Sub

Any body please help me on this issue.

Subject: WebQuerySave Agent Error : Object variable not set

Hi,

It seems you have some trouble with the loop boundaries.

Which line the agent fail ?

Here is a tip to help debug WQS LS agent. It give the error and the line number :

Add this line at top :

On Error Goto failed

At the end of your script :

cleanup:

’ Do some cleanup here if needed.

End

failed:

Msgbox Error & " - Line : " & Erl

Resume cleanup

End Sub

Subject: RE: WebQuerySave Agent Error : Object variable not set

hi antoine

i checked if any problem persists with the loop boundaries and the whole code is working cool in notes client.

but the only problem is when it comes to web.

may be it is concerned with document context or doc.getitemvalue ???

also i had located the error line which is from the agent log and is as below.

12/04/2006 08:13:52 PM Agent message: DB 1 ok

12/04/2006 08:13:53 PM Agent message: view ok

12/04/2006 08:13:53 PM Agent message: web fields ok

12/04/2006 08:13:53 PM Agent message: no;yes;Lotus Inc;

12/04/2006 08:13:53 PM Agent message: 25B7E346B286F4466525721C0024DEBA;36B32E9D800A57D76525723A0019FC1D;FAA95B2A8DBEDE

4B6525723A001A0887;

12/04/2006 08:13:53 PM Agent message: removing the ; from the string containment for document id’s

12/04/2006 08:13:53 PM Agent message: performing split operation for document id’s

12/04/2006 08:13:53 PM Agent message: removing the ; from the string containment for userchosen answers

12/04/2006 08:13:53 PM Agent message: performing split operation for userchosen answer’s

12/04/2006 08:13:53 PM Agent message: initialise correct and wrong score

12/04/2006 08:13:53 PM Agent message: 2

12/04/2006 08:13:53 PM Agent message: 2

12/04/2006 08:13:53 PM Agent message: looping through the document id’s to get the correct answer from DB1 for the question given.

12/04/2006 08:13:53 PM Agent message: 25B7E346B286F4466525721C0024DEBA

12/04/2006 08:13:53 PM Agent message: correct answer is : no

12/04/2006 08:13:53 PM Agent message: user chosen answer is : no

12/04/2006 08:13:53 PM Agent message: answer comparison and score computation

12/04/2006 08:13:53 PM Agent message: 1

12/04/2006 08:13:53 PM Agent message: 36B32E9D800A57D76525723A0019FC1D

12/04/2006 08:13:53 PM Agent message: correct answer is : yes

12/04/2006 08:13:53 PM Agent message: user chosen answer is : yes

12/04/2006 08:13:53 PM Agent message: answer comparison and score computation

12/04/2006 08:13:53 PM Agent message: 2

12/04/2006 08:13:53 PM Agent message: FAA95B2A8DBEDE

4B6525723A001A0887

12/04/2006 08:13:53 PM Agent message: loop terminated

im wondering that i have a document by the unid starting with FAA95… but why iam getting an Object variable not set error.

after performing error handling im getting out of the loop at the last document.

iam going crazy. please drop your suggestion on this i will be very thankfull.

please help me on this…

Subject: WebQuerySave Agent Error : Object variable not set

A little debugging and logging would help a lot. You failed to check to see if doc2 got anything. That is almost certainly indicates that the last value is not a docID.

Instead of letting the the code fail, like this:

Set doc2=vw.GetDocumentByKey(id,True)

correctans=doc2.GetItemValue(“origans”)(0)

you should do some error handling (and debugging) like:

Set doc2=vw.GetDocumentByKey(id,True)

if doc is nothing then

’ probably skip out of the loop here

msgbox “doc2 went past end of loop and is done”

…

else

correctans = doc2.origans(0)

end if

I did didn’t review the code at the top, but, I bet your parsing does not check for some stray text after the last docid.

Subject: RE: WebQuerySave Agent Error : Object variable not set

hello jamie

i agree with you and i did and continue=false followed by Exit sub when doc2 is nothing and i got the agent log as follows

have a look at it

12/04/2006 08:13:52 PM Agent message: DB 1 ok

12/04/2006 08:13:53 PM Agent message: view ok

12/04/2006 08:13:53 PM Agent message: web fields ok

12/04/2006 08:13:53 PM Agent message: no;yes;Lotus Inc;

12/04/2006 08:13:53 PM Agent message: 25B7E346B286F4466525721C0024DEBA;36B32E9D800A57D76525723A0019FC1D;FAA95B2A8DBEDE

4B6525723A001A0887;

12/04/2006 08:13:53 PM Agent message: removing the ; from the string containment for document id’s

12/04/2006 08:13:53 PM Agent message: performing split operation for document id’s

12/04/2006 08:13:53 PM Agent message: removing the ; from the string containment for userchosen answers

12/04/2006 08:13:53 PM Agent message: performing split operation for userchosen answer’s

12/04/2006 08:13:53 PM Agent message: initialise correct and wrong score

12/04/2006 08:13:53 PM Agent message: 2

12/04/2006 08:13:53 PM Agent message: 2

12/04/2006 08:13:53 PM Agent message: looping through the document id’s to get the correct answer from DB1 for the question given.

12/04/2006 08:13:53 PM Agent message: 25B7E346B286F4466525721C0024DEBA

12/04/2006 08:13:53 PM Agent message: correct answer is : no

12/04/2006 08:13:53 PM Agent message: user chosen answer is : no

12/04/2006 08:13:53 PM Agent message: answer comparison and score computation

12/04/2006 08:13:53 PM Agent message: 1

12/04/2006 08:13:53 PM Agent message: 36B32E9D800A57D76525723A0019FC1D

12/04/2006 08:13:53 PM Agent message: correct answer is : yes

12/04/2006 08:13:53 PM Agent message: user chosen answer is : yes

12/04/2006 08:13:53 PM Agent message: answer comparison and score computation

12/04/2006 08:13:53 PM Agent message: 2

12/04/2006 08:13:53 PM Agent message: FAA95B2A8DBEDE

4B6525723A001A0887

12/04/2006 08:13:53 PM Agent message: loop terminated

im wondering that i have a document by the unid starting with FAA95… but why iam getting an Object variable not set error.

after performing error handling im getting out of the loop at the last document.

iam going crazy. please drop your suggestion on this i will be very thankfull.

Subject: RE: WebQuerySave Agent Error : Object variable not set

You still haven’t pinned it down to which line is failing. I cannot match the output to the code. Try an OnError statement which prints Err, Error, and Erl.