How can I run from an agent to another agent running on a different domino server? - lotus-notes

Brief description
We do have multiple Domino Servers (DS). Each DS is hosting several maildatabases. I would like to delete specific mail database. The deletion process gets triggered by an external application, which can run DS agents. The external application can also pass parameters to the agent.
Infrastructure overview
I have 1 notes database (ND) called delete-database.nsf. This ND is replicated with 3 Domino Servers (DS), lets call them DS1, DS2 and DS3.
Workflow
The external application will run the agent1 on DS1 with the parameters mailserver and mailfilename. Let's say the mailserver-parameter-value is DS2 and mailfilename-parameter is mail\doe.nsf .
Due to I can't delete a mail database which is not on same DS like the agent is currently running, I'm calling agent2 on replica database (based on mailserver-paramter) and also passing the mailfilename.
Agent2 should receive the malfilename-parameter and delete the maildatabase, which is located on the same DS like itself.
Question
How can I call from agent1 on DS1 another agent called agent2 on DS2 and also pass parameters like mailfilename.
I tried this, but it doesn't call the agent2 and also not passing the parameters.
Code of agent1:
Dim ses As New NotesSession
Dim db2 As NotesDatabase
Dim agent2 As NotesAgent
Dim docTemp As NotesDocument
Set db2 = New NotesDatabase( "DS2/Certifier", "delete-database.nsf" )
Set agent2 = db2.GetAgent( "agent2" )
Set docTemp = New NotesDocument( db2 )
' Parameters
docTemp.mailfilename = "mail\doe.nsf"
Call agent2.runWithDocumentContext( docTemp )
Code of agent2:
Dim ses As New NotesSession
Dim docTemp As NotesDocument
Dim description As String
Dim mailserver As String
Dim mailfilename As String
Set docTemp = ses.DocumentContext
mailfilename = docTemp.mailfilename
' * Delete mail file part *
' * ... *
' * Delete mail file part *

By far the easiest method is to send the other database an internal mail, with all the info you need. In the other db you create an agent that runs on When mail has arrived, checks whether it comes from the right source, and then executes whatever you need. You only have to set your db up as a mail-in database.

Related

Agent for UnprocessedDocuments After New Mail Arrives

I wish to modify some documents when they arrive in my mail-in application. (I need to remove the $REF field which then allows dragging and dropping in to folders, but that's not the point.)
I have my agent set to After New Mail Arrives and to select unprocessed documents. Designer Help for Unprocessed documents states...
With the agent properties as ....
But the agent selects any document in the Inbox which has been modified or edited rather than just the new arriving email. There is also a delay of up to a minute before the agent runs.
Sub Initialize
Dim session As New NotesSession
Dim db As NotesDatabase
Dim collection As NotesDocumentCollection
Dim doc As NotesDocument
Set db = session.CurrentDatabase
Set collection = db.UnprocessedDocuments
Set doc = collection.GetFirstDocument()
While Not(doc Is Nothing)
If doc.Hasitem("$REF") Then
doc.Subject= "($Ref) " & doc.Subject(0) 'Only testing here will remove item if exists
Else
doc.Subject = "(No Ref) " & doc.Subject(0)
End If
Call doc.save(True,False)
' Call session.UpdateProcessedDoc( doc ) 'This doesn't appear to make any difference.
Set doc = collection.GetNextDocument(doc)
Wend
End Sub
Any help in running this type of script on only new mail and faster than at present, as users may edit the doc before the agent has run, would be appreciated.
Thanks
You might want to use trigger "Before new mail arrives" instead of "After new mail has arrived".
"Before new mail arrives" gets executed for every single new email immediately.
You get access to email document with
Dim session as New NotesSession
Dim doc as NotesDocument
Set doc = session.DocumentContext
You can find a good comparison of both triggers here.
The delay is normal. The agent manager doesn't guarantee immediate execution.
What you might be seeing is a "first-time effect". I.e., the first time you run the agent, all of the messages are "new" because they are newer compared to Last-Run timestamp on the agent - which defaults to day zero in the distant past. Have you tried this multiple times in the same database to see if what is in unprocessed documents on the second run?

Passing of parameter from Database1-Agent to Database2-Agent using Lotusscript

I would like to ask if it is possible to pass parameters (for example: fieldA and fieldB value) from Database1 using an agent, and triggering Database2-agent to accept the parameter being passed?
Not sure if it's possible. Thank you!
There is a -partly undocumented- function to pass a complete in- memory document to an agent without saving it. Like that you can pass anything from one agent to another. But it only works if one agent calls the other:
Dim ses as New NotesSession
Dim db2 as NotesDatabase
Dim agent2 as NotesAgent
Dim docTemp as NotesDocument
Set db2 = New NotesDatabase( "Server", "db2Path.nsf" )
Set agent2 = db2.GetAgent( "NameOfAgent2" )
Set docTemp = New NotesDocument( db2 )
docTemp.Parameter1 = "Some string"
docTemp.Parameter2 = "Another String"
docTemp.AnyNameYouWant = 3
Call agent2.runWithDocumentContext( docTemp )
Then in the agent two you access the document like:
Dim ses as New NotesSession
Dim docTemp as NotesDocument
Set docTemp = ses.DocumentContext
param1 = docTemp.Parameter1
param2 = docTemp.Parameter2
numParam1 = docTemp.AnyNameYouWant

Lotus Notes Database Search

i am trying to write a code to open VBA and do search based on the cell value in A1 (integer). i managed to write a code up to point where i can open the lotus notes and go to specific database. I tried many online codes but couldn't manage to find the code to search in that database. "Lotus.NotesSession" doesn't work the excel version i use. Could you please help me to finish this code. Code is below:
Sub macro4()
Dim uiWs As Object
Dim dbname As String
Dim serverName As String
Dim db As NotesDatabase
Dim doccol As NotesDocumentCollection
Dim varA As Integer
dbname = "***"
serverName = "***"
Set uiWs = CreateObject("Notes.NotesUIWorkSpace")
Call uiWs.OpenDatabase(serverName, dbname)
Set db = uiWs.GetDatabase(serverName, dbname) ---->where i get the error
varA.Value = Sheets("sheet1").Range("A1").Value
Set doccol = db.FTSearch(varA, Nothing, 0)
End Sub
In Notes there are two "parent"- classes to derive everything from. The NotesUIWorkspace is the class for the "frontend": It contains everything that you SEE in the client. The NotesSession is the class for the backend. NotesDatabase is a backend- class. To correctly get your database, you need to use NotesSession:
Set ses = CreateObject("Notes.NotesSession")
Set db = ses.GetDatabase(serverName, dbname)
You mixed up COM and OLE Integration. The thing you tried to use (Lotus.NotesSession) is for COM only and you need to include Notes in your project to use this.
For your example to work you need to use the OLE integration: Notes.NotesSession
Now to your "Search"- Code:
There are two different ways to search a NotesDatabase:
There is the Fulltextsearch and the "normal" search.
The Fulltextsearch just searches for your value everywhere in all documents and returns a collection. A search for "Tom" in a mailfile will find all mails / calendar entries that where:
sent by Tom
received by Tom
have the word "Tom" in subject or body or an attachment of the mail.
The syntax for FTSearch is:
Set doccol = db.FTSearch( YourSearchValue )
You can restrict the search to one certain field by using a special syntax for your search. e.G. to only search in the "From" field you could write
[From] = "YourSearchValue"
In FTSearch the "=" always means "contains"
The normal search uses a Formula (in #Formula- syntax) to search for a document. It needs the right syntax, otherwise it will not find anything. A formula to search all documents that come from "Tom" would be:
#Contains( From ; "Tom" )
The syntax for search is:
Set doccol = db.Search( YourQueryAsExampleAbove, Nothing, 0 )
With Nothing = Cutoffdate (if given only return documents created or modified after the date) and 0 = max. number of documents to return (0 = return everything).
So your example code for the could be something like:
strQuery = "FieldToSearch = " & Sheets("sheet1").Range("A1").Value
Set doccol = db.Search( strQuery, Nothing, 0 )
After calling OpenDatabase successfully, you can use
set uiDb = uiWS.CurrentDatabase
That will get a NotesUIDatabase object, and then you can use
set db= uiDb.Database
That will get you the NotesDatabase object that you need in order to call the FTSearch method.

lotus script to get register use OU and O?

i am trying to get the OU and O from a user ID which is newly created
TestUser1.id
Question: i want to get full path of the new register ID.
1) Without login to that account to return the user ID Information ?
Full path = CN=TestUser1/OU=Software/O=pcs
Sub Initialize
Dim session As New NotesSession
Dim adminp As NotesAdministrationProcess
Set adminp = _
session.CreateAdministrationProcess(mailsvr)
noteid$ = adminp.SetUserPasswordSettings( _
"CN=TestUsesr1/OU=Software/O=pcs", PWD_CHK_LOCKOUT, 0, 0, True)
If noteid$<> "" Then
Dim db As New NotesDatabase(mailsvr, "admin4.nsf")
Dim ws As New NotesUIWorkspace
Call ws.EditDocument(False, db.GetDocumentByID(noteid$))
End If
End Sub
Actually what i really want to do is to force user to first times login an account to force user change his/her http password
i not sure this is the correct way to do it or not for a new created ID?
below link is related with this topic:
force notes user to change password / internet password on next login using lotus script
As already partly answered in your linked question forcing a user to change his internet password is very easy:
Get user document from server names.nsf
set field HTTPPasswordForceChange to "1"
Here is some example code (no error handling, not syntax checked).
From the documentation your adminp- example should work as well, but it will lockout the user and not allow him to login if the server is configured like to check passwords...
Dim db as NotesDatabase
Dim viwUser as NotesView
Dim docUser as NotesDocument
Set db = New NotesDatabase( yourServer, "names.nsf" )
Set viwUser = db.GetView( "($Users)" )
Set docUser = viwUser.GetDocumentByKey( "CN=TestUsesr1/OU=Software/O=pcs" )
Call docUser.ReplaceItemValue( "HTTPPasswordForceChange" , "1" )
Call docUser.Save( True, True, True )

Error connecting to server. The remote server is not a known TCP/IP host during send email

yesterday i have created an agent in lotus script that collects mails and send them to the relatives mail address. i have scheduled it to work automatically on server every 10 minutes but when it runs on notes log appears this errors messages
AMgr: Agent ('agent name' on 'database name') printing: Sending mail...wait
19/09/2014 14:37:12 Error connecting to server 'ServerName': The remote server is not a known TCP/IP host.
19/09/2014 14:37:12 Error connecting to server 'ServerName': The remote server is not a known TCP/IP host.
19/09/2014 14:37:12 AMgr: Agent ('agent name' on 'database name') error message: Notes error: The remote server is not a known TCP/IP host.
I try to add the FQHN of the server to the file 'host' but errors recur; if i ping the mail server using ip address or the name of the mail server from domino server, it responds.
can anyone help me ?
thank
THIS IS THE CODE:
Dim despratica As String
Dim listaambiti As String
Dim am As Integer
Dim notebody As String
Dim s As Integer
Dim valori () As String
Dim itememail As NotesItem
Dim Maildb As New NotesDatabase("","")
Dim Maildoc As NotesDocument
Dim r As Integer
Call Maildb.openmail
Set Maildoc = New NotesDocument( Maildb )
Maildoc.From=doc.tab_email(0)
Maildoc.Subject ="From " & doc.tab_nomeaz(0)
Maildoc.SendTo=""
listaambiti=listaambiti + "-" + doc.ambito(am)
despratica= "nump description"
notebody="body"
Set rtItem = New NotesRichTextItem(Maildoc , "Body" )
Call rtItem.AppendText(notebody)
For s =0 To Ubound(doc.SendTo)
Redim Preserve valori(0 To s)
valori(s)=doc.SendTo(s)
r=0
Forall f In valori
If f= valori(s) Then r=r+1
End Forall
If r=1 Then
Set itememail=Maildoc.GetFirstItem( "SendTo" )
Call itememail.AppendToTextList(valori(s))
Call Maildoc.Send(False,Cstr(valori(s)))
End If
Next
Call Maildoc.save(True,True)
You're using OpenMail(), and even if the agent is set to run on behalf of a specific user, I think this call may still be relying on the notes.ini settings for MailFile and MailServer -- which may not exist in the server's notes.ini file (and even if they did, they wouldn't be for the user you're expecting!). Try using a different method to find and open the user's mail file.
Also, make sure that the server can resolve it's own name. There are a number of problems that can cause this to fail. E.g., I've seen this happen when the DNS configuration on the server is applying the wrong domain suffix to all names, or if it is referring to an 'outside' DNS server but the server's host name is in an 'inside' DNS zone.

Resources