Retrieve documents from mail db through agent

I have an agent which retrieves document from my mail file. When I run the agent manually, it retrieves my mail documents. However, if I set the agent to run in schedule (every 5 mins), it cannot access my mail documents?

Can anybody explain to me why this is happening?

Many Thanks

Subject: Retrieve documents from mail db through agent

um, can you post your code?

Subject: RE: Retrieve documents from mail db through agent

Actually I’ve got the code from The Sandbox…

Here it is…

%REM


Script to load Calendar entries from a user or group to load into a calendar view to see excactly what the appointments are

This script is made 16/6/2001 by René Romijn

Version 0.1 - Initial database, send it to Notes.net.

Version 0.2 - All the dutch keywords are removed.

Version 1.1 - Version Placed on SandBox

Version 1.2 - Minor bugs resolved (9 points fonts for the mac and some conversion errors)

Version 1.3 - Still deleted some Dutch words

				-	Changed some major things in the update process, now it don't throw away all the documents but update only if needed

				-	Thanks must go to Wiebe van Bruggen, he had some nice tricks! 

				-	Check on type of document to included

Version 1.3.1 - Wrong point Userview.GetNextDocument( Userdoc ).

				-	Don't use the db.Search formula, coz the documentcollection is not useable in this kind of action

				-	Use BusyName also in the key, if there is an meeting then there where multiple documents with the same UniversalID

this script is only to be used on mail files that are reside on the same server


Tell the agent that he has to run several times a day and on the server where the mail files resides

If you have comments: r.romijn@zonnet.nl


%ENDREM

Sub Initialize

Dim session As New NotesSession

Dim db As NotesDatabase

Dim Userdb As NotesDatabase

Dim Userview As NotesView

Dim Userdoc As NotesDocument

Dim CompareDoc As NotesDocumentCollection

Dim view As NotesView

Dim CompareView As NotesView

Dim doc As NotesDocument

Dim nxtdoc As NotesDocument

Dim Profiledoc As NotesDocument

Dim TestApp(200) As String         'Assuming that nobody has more then 200 (different!) repeating or overlapping in day's appointments

Dim vc As NotesViewEntryCollection



Print "Import mail entries start: " & Trim( Str$( Now ) )

Set db = session.CurrentDatabase



'Get the profile doc where the config is

Set Profiledoc = db.GetProfileDocument("Settings")



Error_Status="0"



'Setting the date range to look for in the user mail databases

Min=Profiledoc.min

Min=Min(0)

Max=Profiledoc.max

Max=Max(0)

DateMin=Cdbl(Date())-Min

DateMax=Cdbl(Date())+Max



Type_Included=Profiledoc.Type_Included



Set view = db.GetView("($Calendar)")



 'Set on all the documents a flag, if in the end the flag is still "1" then delete the document	

'Check also for documents that fall out the range and delete those documents



Set CompareView = db.GetView("Entries")

Set doc=CompareView.GetFirstDocument

While Not (doc Is Nothing)

	DateRange=doc.CalendarDateTime

	Value=Datevalue(DateRange(0))

	DateRange=Cdbl(Value)

	If DateRange < DateMin Then

		Call doc.Remove(True)

		Set doc=CompareView.GetFirstDocument

	Else

		doc.refresh_calendar="1"

		Call doc.save(True,True)

		Set doc=CompareView.GetNextDocument(doc)

	End If

Wend



Forall i In Profiledoc.mailfiles

	

     'Clear the arry that is needed for the repeating appointments

	Erase TestApp

	

	TestAppCounter=1

	

	Servername=Strleft(i,":")         'Don't use it yet

	Mailfile=Strright(i,":")          'This can only work if a server can reach another server from an agent

	

	On Error Goto OpenDatabase

	

	Print "Opening: " & Mailfile

	

	Set Userdb = New NotesDatabase( Servername, Mailfile )

	Set Userview = Userdb.GetView( "($Calendar)" )

	Set Userdoc = Userview.GetFirstDocument

	

	On Error Goto GeneralError

	

	

	While Not ( Userdoc Is Nothing )

		DatumRange=Userdoc.CalendarDateTime

		Value=Datevalue(DatumRange(0))

		DatumRange=Cdbl(Value)

		If DatumRange > DateMin Then

			If   DatumRange < DateMax Then

				

				If Userdoc.form(0)="Task" Then

					'Skip the task forms, whe don't want to know what someone is doing.

				Else

					Forall k In Type_Included

						If Userdoc.AppointmentType(0)=k Then

							IsIncluded="1"

							Exit Forall

						End If

					End Forall

					If IsIncluded="1" Then

						'Look if we already have a document of this entry

						Owner=Userdoc.GetItemValue("$BusyName")

						CompareUID=Userdoc.UniversalID + Owner(0)

						Set CompareDoc = CompareView.GetAllDocumentsByKey(CompareUID, True)

						

						OldDoc=0

						If CompareDoc.Count>0  Then

							OldDoc=1

						End If

						DateRange=Userdoc.CalendarDateTime

						Value=Datevalue(DateRange(0))

						DateRange=Cdbl(Value)

						

						'Look if we have to deal with repeating appointments, they has to be copied in a different way,

						'coz if you copy them all, they appear multiple times in the calendar view

						

						NumberOfRepeatingDocs=Evaluate("@Elements(CalendarDateTime)",Userdoc)

						If NumberOfRepeatingDocs(0)=1 Then

							If OldDoc=1 Then

								Set doc  = CompareDoc.GetFirstDocument

								'Look if there are changes in the original document

								If doc.LastModifiedInCalendar(0) = Userdoc.LastModified Then

									'Do Nothing

								Else

			  						'there are changes, just copy all the fields rather then checking all the fields!

									Call Userdoc.CopyAllItems( doc, True )

									doc.LastModifiedInCalendar = Userdoc.LastModified

									Owner=Userdoc.GetItemValue("$BusyName")

									doc.originalid = Userdoc.UniversalID+Owner(0)

								End If

							Else

								Set doc = New NotesDocument( db )

								Call Userdoc.CopyAllItems( doc, True )

								doc.LastModifiedInCalendar = Userdoc.LastModified

								Owner=Userdoc.GetItemValue("$BusyName")

								doc.originalid = Userdoc.UniversalID+Owner(0)

							End If

							

							doc.refresh_calendar="0"

							

   						     'Check to see if we copied a private appointment

							If Userdoc.orgconfidential(0)="1" Then

								'Just change the subject to private appointment

								doc.subject="Private appointment" 

							End If

							Call doc.Save( True, True )

						Else

						     'Well, we have an repeating appointment, check if we already processed the document in early stages

							UniqueID=Userdoc.UniversalID

							IsProcessed=0

							For j=1 To TestAppCounter

								If TestApp(j)=UniqueID Then 

									IsProcessed=1

									Exit For

								End If

							Next

							If IsProcessed=0 Then

						          'We store the Appointment Unique ID in an array coz we want this document only one time in the view

								TestApp(TestAppCounter)=UniqueID

								TestAppCounter=TestAppCounter+1

								FirstTime=0

								Forall dates In Userdoc.CalendarDateTime

									If OldDoc=1 Then

										If FirstTime=0 Then

											Set doc  = CompareDoc.GetFirstDocument

											FirstTime=1

										Else

											Set doc = CompareDoc.GetNextDocument(doc)

										End If

										If doc.LastModifiedInCalendar(0) = Userdoc.LastModified Then

											'Do Nothing

										Else

						  					'there are changes, just copy all the fields rather then checking all the fields!

											Call Userdoc.CopyAllItems( doc, True )

											doc.CalendarDateTime=dates             	 'Fool Notes that the start date is different

											doc.LastModifiedInCalendar = Userdoc.LastModified

											Owner=Userdoc.GetItemValue("$BusyName")

											doc.originalid = Userdoc.UniversalID+Owner(0)

										End If

									Else

										Set doc = New NotesDocument( db )	

										Call Userdoc.CopyAllItems( doc, True )  	 'Just copy all items

										doc.CalendarDateTime=dates             	 'Fool Notes that the start date is different

										Owner=Userdoc.GetItemValue("$BusyName")

										doc.originalid = Userdoc.UniversalID+Owner(0)

										If Userdoc.orgconfidential(0)="1" Then

										     'Just change the subject to private appointment

											doc.subject="Private appointment" 

										End If

									End If

									doc.refresh_calendar="0"

									Call doc.Save( True, True )

								End Forall

							End If

						End If

					End If

				End If

			End If

		End If

		IsIncluded="0"

	 ' Get the next user document

		Set Userdoc = Userview.GetNextDocument( Userdoc )    ' Get the next user document

	Wend

OpenDatabaseResume:

End Forall

If Error_Status="0" Then

 'This view shows the entries who has been deleted in the userdatabase, the flag that is set in the beginning is still "1" so delete it	

	Set view = db.GetView("Deleted Entries")

	Set vc = view.AllEntries

	Call vc.RemoveAll( True )

End If

Print "Import mail entries stop: " & Trim( Str$( Now ) )



Exit Sub

GeneralError:

Print "General Failure"



Resume Next

OpenDatabase:

Print "Database from " + Mailfile + " cannot be opened!"

Error_Status="1"

Goto OpenDatabaseResume

End Sub

Subject: Retrieve documents from mail db through agent

Hi Mark ,

Please check few things.

  1. Whether the id which has signed the scheduled agent has got access to run Restricted Lotus Scripts agents on the server or not. If not , get the agent / mail db signed by an id which has access to do so.

  2. The agent should not use any ui classes , eg NotesUIWorkspace , NotesUIView etc

  3. In the ACL of the mail DB , give manager access to the server where the scheduled agent runs / is supposed to run.

Check these , and try.

Best of Luck :-))

Siddhartha

Subject: RE: Retrieve documents from mail db through agent

thanks for the response Siddhartha,If item no. 1 is the case, how come that when I run the agent manually (in designer, right click - run) it retrieves the document. However if it runs on schedule it doesn’t work, I checked the agent log and it actually runs but no documents are retrieved. I am the signer of the agent.

No. 2. the doesn’t use any ui classes.

No. 3. The server has manager access to the mail db.

Are there anymore possible reasons? thanks

Subject: RE: Retrieve documents from mail db through agent

Hi Mark ,

When you run it from the designer , it is the same as running it from the Action menu in the client.

When you run , an agent from the client , Agent manager task is not involved.You access rights to run agents is checked.

Scheduled agent run is a totally different ballgame.

Scheduled agent is run by Agent Mgr task on the domino server. The access rights of the id who has signed this agent is checked.

Ask the Domino Admin , to check the server doc. In the security tab , which id has the access to rin restricted Lotus Script agents on the server. Get the agent signed by the id which has access to run restricted Lotus Script agents , or get ur id added in the server doc under Run restricted LS Agents.

I have a strong feeling , that this is the issue which is preventing scheduled replication.

Bye & keep me posted when u find a solution.

Siddhartha