Variable object not set

Hi can anyone please help. I have an agent that is suppose to run when a certain event has happened. There is a one agent which runs and calls the second agent to run but now the second agent gives this error “Variable object not set”. It gives the error on this line: Set workingDoc = .db.GetDocumentByID(theAgent.ParameterDocID. Here is the code for both agancies.

The first agent:

This function calls the second agent:

Function doAgentRun(aDoc As NotesDocument) As NotesDocument

Dim wDb As NotesDatabase

Dim wAgent As NotesAgent

Dim wDoc As NotesDocument

Dim instructDoc  As NotesDocument

Dim sErr As String

Dim sAgent As String

Dim sWDocId As String

Dim sWDbId As String

Dim bAgent As Integer

Dim sAgentTag As String



On Error Goto EndMe



bAgent = -1

Set doAgentRun = Nothing

sAgent = aDoc.txtAgentName(0)

sWDocId = aDoc.WFWorkingDocID(0)

sWDbId = aDoc.WFDbID(0)



If Len(sAgent) = 0  Then

	sErr = "Aucun nom d'Agent spécifié"

	Goto EndMe

End If



If Len(sWDocId) = 0  Then

	sErr = "L'Identifiant du document de la Base de données n'a pas été trouvé"

	Goto EndMe

End If



If Len(sWDbId) = 0  Then

	sErr = "L'Identifiant du document de la Base de données n'a pas été trouvé"

	Goto EndMe

End If





Set wDb = getDbByReplica(sWDbId,aDoc)

If Not wDb Is Nothing Then

	Set wDoc = wDb.GetDocumentByUNID(sWDocId)

Else

	sErr = "Incapable de repérer la Base de Données: " + sAgent

	Goto EndMe

End If



If wDoc Is Nothing Then

	sErr = "Le Document de Travail n'existe pas: " + aDoc.WFWorkingDocID(0)

	Goto EndMe

End If



Set wAgent = wDb.GetAgent(sAgent)

If wAgent Is Nothing Then

	sErr = "Cet agent indiqué n'existe pas: " + sAgent

	Goto EndMe

End If



Print WFRUNNER + " - Tenter de lancer l' Agent: " + sAgent + " dans la Base de Données: " + wDb.Title

bAgent = wAgent.Run(wDoc.NoteID)



Delete wDoc

Set wDoc = wDb.GetDocumentByUNID(sWDocId)

EndMe:

If Not bAgent = 0 Then

	If Len(sErr) = 0 Then

		If Len(Error$) > 0 Then

			sErr = Error$ + "(" + Cstr(Erl) + ") " + WFRUNNER +", Module:  doAgentRun"

			Print sErr

		Else

			sErr = "Agent  n' a pas terminer, pas d' information." 

		End If

	End If

	aDoc.txtAgentMessage = sErr

	aDoc.txtAgentOK = "2"

Else

	sAgentTag = wDoc.WFAgentOK(0)

	aDoc.txtAgentMessage = wDoc.WFAgentMessage(0)

	aDoc.txtAgentOK =  sAgentTag

	

	If sAgentTag = "1" Then

		aDoc.txtAgentEnd = Now

		aDoc.txtEnd = Now 'agent always run last thus will also end the task

		aDoc.txtAgentOK = "1"

		aDoc.txtComplete ="1"

	End If		

End If



If Not sAgentTag = "1" Then 'still waitng

	Set doAgentRun = aDoc

End If



Call AgentMail(aDoc,sAgentTag,aDoc.txtAgentMessage(0),wDoc)



Call aDoc.Save(True,False)

Exit Function

End Function

The second agent:

Sub Initialize

'-----------------------------------------------------------------------------------------------------------

'* Developer: Cobus Prinsloo

'* Company:  T-Systems

'* Created:     18/08/2002

'* Description:

'This agent will get the current application an all its responses and recreate it in the

'institution database

'-----------------------------------------------------------------------------------------------------------



On Error Goto ErrorHanlder

Dim BasicObj As BasicDeclarations



Dim theAgent As NotesAgent



Dim docProfile As NotesDocument

Dim workingDoc As NotesDocument

Dim docNew As NotesDocument

Dim docInst As NotesDocument

Dim docNewRes As NotesDocument

Dim docRes As NotesDocument

Dim docResRes As NotesDocument

Dim docKwd As NotesDocument



Dim viewI As NotesView

Dim dcI As NotesDocumentCollection



Dim i As Integer

Dim k As Integer



Dim sRepID As String

Dim vRepId As Variant

Dim vStatus() As String



Set basicObj = New BasicDeclarations

Set dbInst = New NotesDatabase("","")



With BasicObj

	Call .LoadBackend

	Set theAgent = .session.CurrentAgent

	Set workingDoc = .db.GetDocumentByID(theAgent.ParameterDocID)

	Set docProfile = .db.GetProfileDocument("databases")'DNT >> Get the databases profile document

	

	vRepID = Evaluate("@ReplaceSubstring(sysLOBins;"":"";"""")",docProfile)'Replace :

	sRepID = vRepID(0)

	

	Call dbinst.OpenByReplicaID(.db.Server,sRepID)'Open the database with the replica id

	

	

	Set .Doc = workingDoc'BasicObj.GetAnyCurrentDocument(False)'Get the current selected/open document

	Set docInst = New NotesDocument(dbInst)'Create new document

	

	Call .Doc.CopyAllItems(docinst)'Copy all item from current doc to new

	

	docInst.Form = "_IF"'DNT >> asign form alias

	Dim docId As String

	Dim bankCode As String

	docId = .Doc.DocID(0)

	'bankCode = GetBankCode(docInst,docId) 'Function in the Generate Bank Code Script Library

	'===============================================

	'New Institution ID Code

	'===============================================

	Dim thisCode As New InstitutionCode

	bankCode = thisCode.getNextCode(Right(.Doc.txtInsttype(0),1))

	'+++++++++++++++++++++++++++++++++++++++++++++++

	'End New Institution ID Code

	'+++++++++++++++++++++++++++++++++++++++++++++++

	docInst.txtBankcode = bankCode 'assign the bank code to the new Institution document

	docInst.txtInSAP = "0"

	.Doc.txtBankCode = bankCode 'write the bank code back to the application document as well

	

	Set docKwd = dbInst.GetProfileDocument("kwk075")

	Call ExplodeList (docKwd.Value(0), ";", vStatus)

	

	docInst.kwdInstStatus = Trim(Right(vStatus(0),Len(vStatus(0)) - Instr(vStatus(0),"|")))

	Call docInst.ComputeWithForm(False,False)'calulate fields

	

	docInst.txtLOBID = .Doc.DocID(0)'Assign the id of the corresponding lob id to this field

	'docinst.txtDocStatus = "Active"'Must change on workflow implementation

	docinst.dtApprovedate = Today

	docInst.dtOperatedate = Today

	docinst.docID = docInst.UniversalID'Reassign docid

	docInst.txtUpdateRaasDb = "1" 'Flag to Create new institution in RAAS

	Call docInst.Save(True,False)'Save

	

	Call CreateFlatFile(bankCode)

	

	.Doc.txtInstID = docinst.DocID(0)'Assign corresponding institution id

	.Doc.txtDocstatus = "1"'To change on wf implementation

	Call .doc.Save(True,False)'save

	Call StripWorkflow(docInst)

	Call .doc.Save(True,False)'save

	Call ApproveChildren(.doc,docInst)

	

End With



workingDoc.WFAgentOK = "1"

workingDoc.WFAgentMessage = "Candidature approuvée pour " & workingDoc.txtInstname(0)



Call workingDoc.Save(True,False)

Exit Sub

ErrorHanlder:

If Not workingDoc Is Nothing Then

	Print "Erreur due à l' Agent: " + theAgent.Name + " - " + Error$ + "(" +Cstr(Erl) +")"

Else

	workingDoc.WFAgentOK = "2" 'Agent found error

	workingDoc.WFAgentMessage = Error$ + " ligne: " + Cstr(Erl) + " Dans agent: " + theAgent.Name 

	Call workingDoc.Save(True,False)

End If

Exit Sub

End Sub

Any help would much appreciated. I have looked on Notes help and on the postings in the forum but I haven’t been lucky to get a solution. Thanks in advance for your help.

Subject: Variable object not set

Assuming this is Lotus Script (?) I’m also assuming you have a user defined object called ‘BasicDeclarations’ as that’s not part of the Notes Object Model. You’re calling a method from it called LoadBackend, I assume this set’s up your environment declaring your session object and db, if db has not been correctly set during this call this might be why you’re getting a object variable not set on that line.

Subject: RE: Variable object not set

Hi Thanks for your response. The BasicDeclaration is a class in the Lotus Script I’m using and the LoadBackend is a sub in that class where the session and the database are declared.

Subject: Variable object not set

Set workingDoc = .db.GetDocumentByID(theAgent.ParameterDocID).

Without reading through all your script, ‘object variable not set’ always means the same thing.‘I don’t have one of the things you are trying to use’.

Use your debugger. This just means that you don’t have either:

workingDoc, db, or theAgent.

Just track your code and find out why you are not getting one of them.

Dave

Subject: RE: Variable object not set

Thanks for your response. It does find the db and theAgent but it does not seem to find the workingDoc. My problem is I have this database on three languages and it runs perfectly on the English and Portuguese databases but not on the French version. The code is the same for all languages. I have tried debbugging the agent and it shows me that the ParameterDocID value is empty on which I assume the workingDoc is not passed to the second agent. If I could only understand what happens to the workingDoc when it comes to the agent being called by the first one. Thanks.