Scheduled agent to Approve Replica Deletion

Hi I have been asked to create a scheduled agent which would approve the “Replica Deletion” requests in the admin4.nsf database. In this way, the roaming folders of the deleted users will get deleted.

Please let me know if any one has got any experience in this type of agent

Thanks and Regards

Kiran

Subject: Scheduled agent to Approve Replica Deletion

This agent is execute from one db where user terminations are created by HelpDesk users and ; this DB creates an admin request on Admin4.nsf using NotesAdministrationProcess Notes class.

The agent checks for pending mailfile deletions since HelpDesk can specify for how long the mailfile should be kept on the server.

Sub Initialize

%REM

Description: - This agent takes termination requests where a future date was selected for mail file deletion.

			- Gets Pending Approval request from Admin4.nsf and approve it

%END REM

Dim session As New NotesSession

Dim db As NotesDatabase, Admin4Db As NotesDatabase

Dim Ad4View As notesview

Dim docs As NotesDocumentCollection, dc As NotesDocumentCollection, responses As NotesDocumentCollection 

Dim doc As notesdocument, docAd4 As NotesDocument 

Dim adminp As NotesAdministrationProcess

Dim notesName As NotesName 

Dim item As NotesItem

Dim strsearch As String 

Dim count As Integer 



Set db = session.CurrentDatabase 

REM Gets Pending requests less or equal than system's date

strsearch = "Form = ""Termination"" & Status = ""Scheduled"" & DateDeletion <= [" + Cstr(Today) + "]"	

Set docs = db.Search(strsearch, Nothing,0)



REM Exit if nothing match with today's date

If docs.Count = 0 Then Exit Sub



Set doc = docs.GetFirstDocument

Set Admin4Db = New NotesDatabase(doc.RegistrationServer(0), "admin4.nsf")

Set Ad4View = Admin4Db.getview("All Requests by Name")

REM Get all Termination Requests

While Not doc Is Nothing	

	REM For each request process all UserNames

	Set item = doc.GetFirstItem("UserName")

	Forall  user In item.Values

		Set notesName = New notesname (user)			

		Set dc = Ad4View.getalldocumentsbykey(notesName.Abbreviated, True)

		REM Loockup for Request on admin4.nsf

		Set docAd4 = dc.GetFirstDocument		

		While Not docAd4 Is Nothing

			REM Get Mail File Deletion request

			If docAd4.ProxyAction(0) = "22" Then

				REM Check if admin4 request was approved

				Set responses = docAd4.Responses

				If responses.Count = 0 Then	' Request hasn't been approved

					Set adminp = session.CreateAdministrationProcess(doc.RegistrationServer(0))

					Call adminp.ApproveMailFileDeletion(docAd4.NoteID)						

				End If					

			End If

			REM Get Next Admin4 Request

			Set docAd4 = dc.GetNextDocument(docAd4)

		Wend

	End Forall

	REM Mark Termination request as Completed when agent runs the second time at 5:00 PM

	If Hour(Today) = 17 Then			

		doc.Status = "Completed"

		Call doc.Save(True, False)			

	End If

	REM Get Next Termination Request

	Set doc = docs.GetNextDocument(doc)

Wend	

End Sub