Agent is not selecting all documents

Hi,I have agent to run on all documents in view,but it is picking up only few doc. For example i have 100 documents when i run this agent it should select 100 documents and complete the task but it is selecting 20 docs in first run then 10 docs in second run like this. Could you please help what would be the problem in my code below.

Note: i have tried all the options(all docs in db, all new & modi docs etc) in agent trigger but still same problem.

Sub Initialize

Dim s As NotesSession

Dim db As NotesDatabase

Set s = New NotesSession

Set db=s.CurrentDatabase

Dim view As NotesView

Dim doc As NotesDocument

Dim uname As Variant

vname = Inputbox(“enter view name”)

Set view = db.GetView( vname )

Set doc = view.GetFirstDocument

Dim BigString As String, LittleString As String

Dim nam As NotesName

While Not ( doc Is Nothing )

Set nam = s.CreateName(doc.from(0))

LittleString =nam.Abbreviated

bigstring = doc.subject(0)

If Instr(doc.subject(0),LittleString) Then

'Msgbox " found"

Call doc.PutInFolder(“UN Match”)

Call Doc.RemoveFromFolder(“Folder1”)

'Set doc = view.GetNextDocument(doc)

'End If

Else

'If Not Instr(doc.subject(0), LittleString) Then

'Msgbox “Not Found”

Call doc.PutInFolder(“UN Not Match”)

Call Doc.RemoveFromFolder(“folder1”)

'Set doc = view.GetNextDocument(doc)

End If

Set doc = view.GetNextDocument(doc)

Wend

End Sub

Subject: Agent is not selecting all documents

try using “View.GetAllEntries” and loop through each entry. In this way you’ll also be able to verify the number of documents in the view while debugging.

hth

Sharjeel.

Subject: RE: Agent is not selecting all documents

Thanks for your response, still same problem

Subject: Agent is not selecting all documents

Use view.Refresh before view.GetFirstDocument

Subject: RE: Agent is not selecting all documents

thanks for your response, if you put view.refresh before view.getfirstdoc it refresh view only once before entering to loop. it’s doesn’t help

Subject: RE: Agent is not selecting all documents

Are you sure current user has read and write access for all documents in view?

Subject: RE: Agent is not selecting all documents

current user has manager access.I am running this agent on local copy

Subject: RE: Agent is not selecting all documents

Having manager access doesn’t mean the user can see all the documents. If the reader field is set, it can be hidden from the user.

Having said that, I THINK what you’re running into is the classic case of your agent losing it’s place because when you get the next document the current document is no longer in the view/folder.

Create a second notesdocument and assign it to the next document before you remove / delete things and then at the end of the loop assign Set doc = nextdoc.

Subject: RE: Agent is not selecting all documents

Sorry, it’s not working

If Instr(docA.subject(0),LittleString) Then

Call docA.PutInFolder(“UN Match”)

Set docB = view.GetNextDocument(docA)

Call docA.RemoveFromFolder(“Folder”)

Set DocA = view.getnextdocument(DocA)

Loop

Subject: You can place your code here

You can place your code here to analyze it

Subject: RE: You can place your code here

The agent trigger ( all docs in view)

Sub Initialize

Dim s As NotesSession

Dim db As NotesDatabase

Set s = New NotesSession

Set db=s.CurrentDatabase

Dim view As NotesView

Dim doc As NotesDocument

Dim uname As Variant

dim docB as notesdocument

vname = Inputbox(“enter view name”)

Set view = db.GetView( vname )

Set doc = view.GetFirstDocument

Dim BigString As String, LittleString As String

Dim nam As NotesName

While Not ( doc Is Nothing )

Set nam = s.CreateName(doc.from(0))

LittleString =nam.Abbreviated

bigstring = doc.subject(0)

If Instr(doc.subject(0),LittleString) Then

'Msgbox " found"

Call doc.PutInFolder(“UN Match”)

Set docB = view.GetNextDocument(doc)

Call Doc.RemoveFromFolder(“Folder1”)

Else

Call doc.PutInFolder(“UN Not Match”)

'Set docB = view.GetNextDocument(doc)

Call Doc.RemoveFromFolder(“folder1”)

End If

Set doc = view.GetNextDocument(doc)

Wend

End Sub

Subject: Use counters and new empty folders for documents

Perhaps you count view entries instead of view documents to check the result.

Try this modified code:

Option Public

Option Declare

Sub Initialize

Dim s As NotesSession

Dim db As NotesDatabase

Set s = New NotesSession

Set db=s.CurrentDatabase

Dim view As NotesView, fld As NotesView

Dim doc As NotesDocument

Dim uname As Variant

Dim docB As notesdocument

Dim vname As Variant



Dim n_counter%, n_counter_1%	, n_counter_2%				' E.N.

Dim s_prefix$, s_text$													' E.N.

s_prefix = Format(Now, "yymmddhhnnss")						' E.N.



vname = Inputbox("enter view name")

Set view = db.GetView( vname )

Set doc = view.GetFirstDocument

Dim BigString As String, LittleString As String

Dim nam As NotesName



While Not ( doc Is Nothing )

	n_counter = n_counter + 1											' E.N.

	Set nam = s.CreateName(doc.from(0))

	LittleString =nam.Abbreviated

	bigstring = doc.subject(0)

	

	If Instr(doc.subject(0),LittleString) Then

		'Msgbox " found"

		Call doc.PutInFolder(s_prefix + " Matched", True)		' E.N.

		'Set docB = view.GetNextDocument(doc)					' E.N.

		'Call Doc.RemoveFromFolder("Folder1")					' E.N.

		

	Else

		Call doc.PutInFolder(s_prefix + " Unmatched", True)	' E.N.

		'Set docB = view.GetNextDocument(doc)

		'Call Doc.RemoveFromFolder("folder1")					' E.N.

	End If

	Set doc = view.GetNextDocument(doc)

Wend



Print "View " + view.Name + " has " _

+ Cstr(n_counter) + " document(s)"									' E.N.

Set fld = db.GetView(s_prefix + " Matched")						' E.N.

n_counter_1 = count_view_folder_docs(fld)						' E.N.

Print "Folder " + fld.Name + " has " _

+ Cstr(n_counter_1) + " document(s)"								' E.N.

Set fld = db.GetView(s_prefix + " Unmatched")					' E.N.

n_counter_2 = count_view_folder_docs(fld)						' E.N.

Print "Folder " + fld.Name + " has " _

+ Cstr(n_counter_2) + " document(s)"								' E.N.	

If n_counter = n_counter_1 + n_counter_2 Then				' E.N.	

	s_text = " is equal to "													' E.N.	

Else																				' E.N.	

	s_text = " IS NOT EQUAL TO "										' E.N.	

End If																			' E.N.	

s_text = Cstr(n_counter) + s_text + Cstr(n_counter_1) _

+ " + " + Cstr(n_counter_2)												' E.N.	

Msgbox s_text																' E.N.	

End Sub

Function count_view_folder_docs(v As NotesView) As Integer ’ E.N.

On Error Goto ErrLab



Dim FR%

Dim doc As NotesDocument



If v Is Nothing Then Goto EndLab



Set doc = v.GetFirstDocument

Do Until doc Is Nothing

	FR = FR + 1

	Set doc = v.GetNextDocument(doc)

Loop	



' End of Function

count_view_folder_docs = FR

EndLab:

Exit Function

ErrLab:

Msgbox "Line " + Cstr(Erl) + " Error " + Cstr(Err) + Chr(13) + Error

Goto EndLab

End Function

Subject: RE: Use counters and new empty folders for documents

Thanks for your code, But still the same problem there no difference with this new code and more over it is creating new folders whenever agent runs, I modified the code but still same problem.

Subject: What is the difference…

What is the result of operation (n_counter - (n_counter_1 + n_counter_2)) in your case?

Subject: RE: What is the difference…

if i have 2 docs in my view where i am selecting the docs and other 2 views have 15 + 2 docs. now the result shows “2 is not equal to 17+0” but still it is not moving all the docs.Here i didn’t understand why it is counting the docs from other views

Subject: Send the database template to me

You can send the database template to my email elenanefedova@gmail.com (if it does not contain a secret).I’ll test it with my own hands.