Manage Learn to apply best practices and optimize your operations.

Allowing users to run background agents from buttons

With the new RunOnServer method of NotesAgnt you can call a background agent from a button.

With the new RunOnServer method of NotesAgnt you can call a background agent from a button. This has the benefit of letting a user do an activity that is usually out of their security realm. In our instance, we wanted to let the user change the DB.Title but we didn't want to give them Manager access to the datbase. The RunOnServer method lets you do it.


First you need a background Agent. This agent has been signed with the relevant access to run on the server. Notice the "agent.ParameterDocID". This is a handle to the document context from where the agent was called from. This agent basically changes the database title after finding the database on the server from a field in the docment.

Sub Initialize
	Dim s As New NotesSession
	Dim agent As NotesAgent
	Set agent = s.CurrentAgent
	Dim dbAccess As NotesDatabase
        Dim doc As NotesDocument
	Dim viewAdmin As Notesview
	Dim docAccessProfile As NOtesDocument
	Dim strRepId As String, strServer As String, strCurrServer As String, strPath As String
	
	Set dbAccess = s.CurrentDatabase
	Set doc = dbAccess.GetDocumentByID(agent.ParameterDocID)
	
	strrepid = doc.tsetupdbid(0)
	If strrepid = "" Then
		Messagebox "Unable to locate replica id of case.", MB_OK, "E R R O R"
		End
	End If
	
	'get the profile document for the access db which contains the server
	Set viewAdmin = dbAccess.GetView("AllbyForm")
	Set docAccessProfile = viewAdmin.GetDocumentByKey("accessprofile")
	strserver = docAccessProfile.Server(0)
	strPath = doc.tCLExtranetCasePathFileName(0)
	
	Dim dbCase As New NotesDatabase( strServer, strPath )
	If dbCase Is Nothing Then End
	dbCase.Title = doc.case_nme(0)
End Sub

Then you need a button that calls the Agent. Notice that we pass the NoteID of the document we are working with. eg "agent.RunOnServer(doc.NoteID)" This allows us to work with the document in the backend. This is an optional parameter but can be very useful.

Sub Click(Source As Button)
	Dim w As New NotesUIWorkspace
	Dim s As New NotesSession     
	Dim dbCase As NotesDatabase
	Dim dbAccess As NotesDatabase
	Dim dcSelected As NotesDocumentCollection
	Dim doc As NotesDocument
	Dim uidoc As NotesUIDOcument
	Dim strcurrServer As String
	Dim strserver As String
	Dim strfile As String
	Dim CaseName As String
	Dim viewAdmin As NotesView
	Dim docAccessProfile As NotesDocument
	Dim strRepID As String
	Dim view As NotesVIew
	
	Set dbCase = New NotesDatabase("", "")
	Set dbAccess = s.currentdatabase
	
	strcurrserver = dbAccess.server
	
	Set doc = s.DocumentContext
	
     ' get new case name and save the document as that...'
	casename = Inputbox("Please enter the new case name:", "Change Case Name")
	If casename = "" Then
		Exit Sub
	End If
	Print "Changing Case Name..."	
	doc.case_nme = casename
	Call doc.save(True, True)
	
	Dim agent As NotesAgent
	Set agent = dbAccess.GetAgent("(RenameDBTitle)")
	If agent.RunOnServer(doc.NoteID) = 0 Then
		Print "Case Name changed to '" & casename & "'"
	Else
		Print "Case Name change failed!"
	End If
	
        Call w.ViewRefresh
	
End Sub

NB The background agent should be set to Run from Agent List and Run Once.

Cheers
Ben

Dig Deeper on Lotus Notes Domino Administration Tools

SearchWindowsServer
Search400
  • Favorite iSeries cheat sheets

    Here you'll find a collection of valuable cheat sheets gathered from across the iSeries/Search400.com community. These cheat ...

SearchDataCenter
SearchContentManagement
Close