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

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

Related

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

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.

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 )

Retrieving changes made by a Java Agent on a document

I am passing parameters to a Java agent from Lotus Script like this:
Set db = session.CurrentDatabase
Set doc = db.CreateDocument
Set uiDoc = workspace.CurrentDocument
Call doc.AppendItemValue("fileName", "SomeString" )
Call doc.Save(True, False)
Set MyAgent = db.GetAgent("AgentName")
Call MyAgent.Run(doc.NoteID)
Set session = New NotesSession
Set db = session.CurrentDatabase
result = doc.GetItemValue("Result")(0)
The agent says the following in Java:
Session session = getSession();
AgentContext agentContext = session.getAgentContext();
Agent agent = agentContext.getCurrentAgent();
Database db = agentContext.getCurrentDatabase();
Document doc = db.getDocumentByID(agent.getParameterDocID());
String fileName = doc.getItemValueString("fileName");
doc.appendItemValue("Result","MyResult");
doc.save();
The agent is doing his job correctly. I checked the parameter document and it indeed contains the results from the agent. However, my form is not able to read the Result parameter.
You have to save the doc in your Java code and to re-read your doc in LotusScript after calling your agent.
It is easier to use an In-Memory Document though:
LotusScript
MyAgent.RunWithDocumentContext(doc, doc.NoteID)
Java
Document doc = agentContext.getDocumentContext()
If for some reason you cannot use RunWithDocumentContext (in earlier versions of Lotus Notes) then you need to reopen document:
Set db = session.CurrentDatabase
Set doc = db.CreateDocument
Call doc.AppendItemValue("fileName", "SomeString" )
Call doc.Save(True, False)
noteID$ = doc.NoteID
Set MyAgent = db.GetAgent("AgentName")
Call MyAgent.Run(noteID$)
'Delete document from memory.
Delete doc
'Get updated document.
Set doc = db.GetDocumentByID(noteID$)
result = doc.GetItemValue("Result")(0)

Out of office service activation with an run on server agent

Is there an documentation or an easy solution how i can activate the out of office service in an user mailfile with an external run on server agent?
I tried it like this, but it does not work...
Dim s As New NotesSession
Dim db As NotesDatabase
Dim doc As NotesDocument
Dim dt As New NotesDateTime(Now)
Set db = s.Getdatabase("SERVERNAME", "MAILFILE")
Set doc = db.Createdocument()
doc.AppointmentType= "2"
doc.BookFreeTime = ""
doc.CreatedByAgent = "1"
doc.ExcludeFromView = "D"
doc.Form = "Appointment"
doc.From = s.Username
doc.Principal = s.Username
Call doc.Replaceitemvalue("$BusyName","")
Call doc.Replaceitemvalue("$BusyPriority","")
Call doc.Replaceitemvalue("$PublicAccess","1")
doc.ApptUNID = doc.Universalid
Call dt.Adjustday(-5)
set doc.EndDate = dt
set doc.EndDateTime = dt
call dt.Adjustday(10)
set doc.StartDate = dt
set doc.STARTDATETIME = dt
doc.Subject = "Out Of Office"
Call doc.Replaceitemvalue("$UpdatedBy",s.Username)
Call doc.save(True,False)
Set doc = db.Getprofiledocument("OutOfOfficeProfile")
Call dt.Adjustday(-5)
Set doc.FirstDayOut = dt
Call dt.Adjustday(10)
Set doc.FirstDayBack = dt
doc.CurrentStatus = "1"
doc.GeneralSubject = "HE IS NOT AVAILABLE"
Call doc.save(True,false)
UPDATE (changed answer from Out of office agent activation to Out of office service activation):
Look in MailFile ScriptLibrary OutOfOfficeLib in Class OutOfOfficeObj for method EnableService(). There is the code you have to adapt and put in your agent.
With the code line
Call db.SetOption( DBOPT_OUTOFOFFICEENABLED, True)
you activate the Out of Office service. There are some other settings you probably have to do in addition. Just follow the called methods in EnableService() and figure out what is really necessary.
Here is a good description how to activate and how to deal with issues with Out of Office service. Changes in users Out of Office service status e.g. might be visible only after sending the user an email.
This is the way how it works.
Dim db As NotesDatabase
Dim doc As NotesDocument
Dim dt As New NotesDateTime(Now)
Set db = s.Getdatabase("SERVER", "MAILFILE")
Set doc = db.Getprofiledocument("OutOfOfficeProfile")
Call dt.Adjustday(-5)
Set doc.FirstDayOut = dt
Set doc.StartTime = dt
Call dt.Adjustday(10)
Set doc.FirstDayBack = dt
Set doc.EndTime = dt
doc.CurrentStatus = "1"
doc.GeneralSubject = "MESSAGE"
doc.TaskState = "1"
doc.CurrentSate = "1"
doc.ShowHours = ""
Call doc.Computewithform(false, false)
Call doc.save(True,false)
Call db.SetOption( DBOPT_OUTOFOFFICEENABLED, True)

Resources