Script Timing Out

I have a database that imports a large number of assets (around 28,000) through an import agent. The agent imports the assets from a CSV file. Once the assets are in the database, I run another agent to find who is responsible for each asset. I think the agent that looks up the responsible party is timing out because the agent works perfectly on a smaller scale version (20 assets).

Can someone let me know if there is a timeout on this type of agent and how I can get around it? Or could someone let me know if it’s the code itself? I’m not exactly a script pro, I just know enough to be dangerous.

The script for looking up the person responsible is below.

Thanks!

Dim Session As New NotesSession

Dim db As NotesDatabase

Dim doc As NotesDocument

Dim uidoc As notesuidocument

Dim ws As NotesUIWorkspace

Dim vw As NotesView

Dim coverage_vw As NotesView

Set db = session.currentdatabase

Set vw = db.GetView(“Current Universe”)

Set coverage_vw = db.GetView(“Coverage”)

Set doc = vw.GetFirstDocument

Const NotesMacro1$ = “@GetProfileField(‘db profile’; ‘RTP_focal’)”

RTP_focal=Evaluate(NotesMacro1$, doc)

Const NotesMacro2$ = “@GetProfileField(‘db profile’; ‘Pgh_focal’)”

Pgh_focal=Evaluate(NotesMacro2$, doc)

Do Until Doc Is Nothing

'check for RTP assets

If doc.Asset_Work_Loc(0) = “USSMB” Then

If doc.Asset_Bldg_num(0) = “500” Then

doc.Asset_Focal = RTP_focal

Call doc.Save( False, False )

End If

If doc.Asset_Bldg_num(0) = “501” Then

doc.Asset_Focal = RTP_focal

Call doc.Save( False, False )

End If

If doc.Asset_Bldg_num(0) = “502” Then

doc.Asset_Focal = RTP_focal

Call doc.Save( False, False )

End If

If doc.Asset_Bldg_num(0) = “503” Then

doc.Asset_Focal = RTP_focal

Call doc.Save( False, False )

End If

End If

'check for Pittsburgh assets

If doc.Asset_Work_Loc(0) = “USPTT” Then

doc.Asset_Focal = Pgh_focal

Call doc.Save( False, False )

End If

'lookup focal points for each AIM site

If doc.Asset_Focal(0) = “unknown” Then

Key = doc.Asset_Site(0)+“-”+doc.Asset_Rcostctr(0)

Eval = PerformDbLookupLS(coverage_vw,Key,2)

If Eval(0) <> “” Then

doc.Asset_Focal = Eval

Call doc.Save( False, False )

End If

'lookup assets owned by customers

If doc.Asset_Focal(0) = “unknown” Then

If doc.Asset_Loc_Type(0) = “C” Then

doc.Asset_Focal = “Customer Asset”

Call doc.Save( False, False )

End If

If doc.Asset_Bldg_Num(0) = “CUST” Then

doc.Asset_Focal = “Customer Asset”

Call doc.Save( False, False )

End If

End If

'lookup assets owned by vendors

If doc.Asset_Focal(0) = “unknown” Then

If doc.Asset_Loc_Type(0) = “V” Then

doc.Asset_Focal = “Vendor Asset”

Call doc.Save( False, False )

End If

End If

'lookup loaner assets

If doc.Asset_Focal(0) = “unknown” Then

If doc.Asset_Loc_Type(0) = “L” Then

doc.Asset_Focal = “Loaner Asset”

Call doc.Save( False, False )

End If

End If

End If

Set Doc = vw.GetNextDocument(Doc)

Loop

Subject: Script Timing Out

I don’t think we are seeing all of your code. What is PerformDbLookupLS in the below line?

Eval = PerformDbLookupLS(coverage_vw,Key,2)

Subject: RE: Script Timing Out

sorry for not including this part of the script. I found this code on one of the boards here. Works really well!

Function PerformDbLookupLS( view As NotesView, sKey As Variant , vFind As Variant ) As Variant

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

’ PerformDbLookupLS function

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

’ There is a perform db lookup function that uses @functions

’ that has a limit of 64k… This one uses ls

Redim strReturnValuesArr( 0 ) As Variant

’ keep the view order, use view entry collection

Dim vec As NotesViewEntryCollection

Set vec = view.GetAllEntriesByKey( sKey, True )

Dim ve As NotesViewEntry

If vec.Count <> 0 Then ’ as Long as we have results…

Set ve = vec.GetFirstEntry()

Redim strReturnValuesArr( 0 To vec.Count-1 ) As Variant

Dim i As Integer

i = -1

If Typename( vFind ) = “STRING” Then

Do While Not ve Is Nothing

i = i + 1

strReturnValuesArr(i) = Join(ve.Document.GetItemValue(vFind),“;”)

Set ve = vec.GetNextEntry(ve)

Loop

Else

’ we want a view column number. hmmmm

Do While Not ve Is Nothing

i = i + 1

strReturnValuesArr(i) =ve.ColumnValues(vFind-1) ’ -1 as cols are 0 based

Set ve = vec.GetNextEntry(ve)

Loop

End If ’ typename is string

End If ’ vec = 0

PerformDbLookupLS = strReturnValuesArr

ExitPoint:

Exit Function

End Function

Subject: RE: Script Timing Out

I recently had a similar problem using GetAllEntriesByKey. I needed to compare a person doc in 2 different dbs to see which 1 had the more recent modified date. Since I knew there was only 1 unique doc for each person I used GetDocumentByKey instead of GetAllEntriesByKey. There are about 5000 records to search. Instead of taking over 1 hour to run it now runs for only 1 minute. You may want to have a look at that if you can change it.

Subject: RE: Script Timing Out

Also instead of going document by document use view entry collection which will be pretty much faster. And there seems to be heavy save volume on one document. Hence need to be reduced to one save per document. Here is the simplified version of the same code. Got some time to look into it.

Make sure the coverage view is indexed and has the first column (key column) sorted.


Dim Session As New NotesSession

Dim db As NotesDatabase

Dim doc As NotesDocument

Dim uidoc As notesuidocument

Dim ws As NotesUIWorkspace

Dim vw As NotesView, coverage_vw As NotesView

Dim vc As NotesViewEntryCollection

Dim e As NotesViewEntry

Dim docsave As Integer

Dim Eval As Variant



Set db = session.currentdatabase 

Set coverage_vw = db.GetView("Coverage")

Set vw = db.GetView("Current Universe")

Set vc = vw.AllEntries



If Not vc Is Nothing Then

	Set e = vc.GetFirstEntry()

	Const NotesMacro1$ = "@GetProfileField('db profile'; 'RTP_focal')"

	RTP_focal=Evaluate(NotesMacro1$, doc)

	

	Const NotesMacro2$ = "@GetProfileField('db profile'; 'Pgh_focal')"

	Pgh_focal=Evaluate(NotesMacro2$, doc)

	

	Do Until e Is Nothing 

		Set doc = e.Document

		

		'check for RTP assets

		If (doc.Asset_Work_Loc(0) = "USSMB" and (doc.Asset_Bldg_num(0) = "500" Or doc.Asset_Bldg_num(0) = "501" Or doc.Asset_Bldg_num(0) = "502" Or doc.Asset_Bldg_num(0) = "503")) Then

				doc.Asset_Focal = RTP_focal

				docsave = True

			End If

		

		'check for Pittsburgh assets

		If doc.Asset_Work_Loc(0) = "USPTT" Then 

			doc.Asset_Focal = Pgh_focal

			docsave = True	

		End If

		

		'lookup focal points for each AIM site

		If doc.Asset_Focal(0) = "unknown" Then

			Key = doc.Asset_Site(0)+"-"+doc.Asset_Rcostctr(0)

			Eval = PerformDbLookupLS(coverage_vw,Key,2)

			If Eval(0) <> "" Then

				doc.Asset_Focal = Eval

				docSave = True

			End If

			

			'lookup assets owned by customers/vendors/laner assets

			If doc.Asset_Loc_Type(0) = "C"  Or doc.Asset_Bldg_Num(0) = "CUST" Then

				doc.Asset_Focal = "Customer Asset"

				docSave = True

			Elseif doc.Asset_Loc_Type(0) = "V" Then

				doc.Asset_Focal = "Vendor Asset"

				docSave = True

			Elseif doc.Asset_Loc_Type(0) = "L" Then

				doc.Asset_Focal = "Loaner Asset"

				docSave = True

			End If				

		End If

		If docSave Then Call doc.Save( False, False )

		Set e = vc.GetNextEntry(e)

	Loop

End If

Subject: Worked like a charm!

Thank you everyone for your help. Much appreciated!

Subject: RE: Script Timing Out

There is a field in the server document under server tasks, agent manager, labeled:

Max LotusScript execution time:

Default is normally 15 minutes. If this is your issue, you will also see an entry in your log.nsf indicating that the max timeout has been exceeded when the agent runs.

Subject: RE: Script Timing Out

I’m getting the timeout on a local replica as well. Is there a line in the local INI file that needs changed as well?

Subject: RE: Script Timing Out

No, this setting is for server based agents - never had a timout problem running local agents and many have run for hours.

What is the error message (timeout) you are getting when running on a local replica?

Subject: RE: Script Timing Out

Tom, Thanks for reponding back and helping out.

What happens is with the 20 asset sample, let’s say asset 1 gets set to being covered by Raleigh.

In the full version (the 28k records) the same asset never gets changed to being covered by Raleigh.

Subject: RE: Script Timing Out

I would put some debug code (the stop command) in and run it with debugger turned on.

Logically, it would a single line of code

If Asset1 then stop

Then you can step through the code and figure out where the hangup is.