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

Start the conversation

Send me notifications when other members comment.

Please create a username to comment.

-ADS BY GOOGLE

SearchWindowsServer

Search400

  • iSeries tutorials

    Search400.com's tutorials provide in-depth information on the iSeries. Our iSeries tutorials address areas you need to know about...

  • V6R1 upgrade planning checklist

    When upgrading to V6R1, make sure your software will be supported, your programs will function and the correct PTFs have been ...

  • Connecting multiple iSeries systems through DDM

    Working with databases over multiple iSeries systems can be simple when remotely connecting logical partitions with distributed ...

SearchDataCenter

SearchContentManagement

Close