OpenNTF.org - Allowing users to run backgrou
My Links (Not logged in)
Code Bin Search
 
Hosted by Prominic.NET
Rate This Code
5 - brilliant stuff
4 - very nice
3 - average
2 - needs work
1 - bad
   OpenNTF Code Bin
About This Code
Brief Description:
Allowing users to run background agents from buttons 
Rating:
Rating: 3 , Number of votes: 1 
Contributor:
Andrew Jones 
Category:
Lotusscript 
Type:
 
Last Modified:
17 Jun 2002 
OpenNTF Disclaimer

All of the program code and information presented in the OpenNTF.org Code Bin are provided "as-is", and should be used at your own risk. OpenNTF.org make no express or implied warranty about anything in the Code Bin, and OpenNTF.org will not be responsible or liable for any damage caused by the use or misuse of anything from this site. OpenNTF.org makes no guarantees about anything. Please thoroughly test all of the knowledge and code you find here before you attempt to use them in your production environment.

Code / Description

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.



Usage / Example
 Comments

No documents found

 Add your comment!