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)
Related
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
Before this I have post a question regarding my problem but still no answer. I will try again to post question about my problem in here. I will update new code and explaination about it. Before this I have done with dialog box, but I have been asked to change it, just use form in view.
My process start with open a form in view to set a new batch info. the form name is PCBatchInfo. In this form, I have 4 field which is BBatchNo, BInspector, BStart, and BEnd. Then in this form I have a button. When I click this button, it will do three process which is:
Create new batch info and save. This is current open document. I call this "dialogDoc".
Then, create a copy of Computer document. In this copy, it will replace BBatchNo as I created just now. I call this copy document as "newdoc" and original document as "doc"
After that, I create new report document and copy value from Computer document. Then I will get value from set batch no which is BInspector, BStart, and BEnd and insert into this report I call this "repdoc".
Below here my lotusscript in my button
Set db = session.CurrentDatabase
Set uidoc = ws.CurrentDocument
Set dialogDoc = uidoc.Document
Set view = db.GetView("Computer")
Set doc = view.GetFirstDocument
If doc.PStatus(0) = "Lock" Then
Msgbox "Complete PC Inspection first!"
Exit Sub
Else
'--set new batch info--'
dialogDoc.Form = "PCBatchInfo"
Call uidoc.FieldSetText("SaveOptions", "1")
Call uidoc.Save
answer% = Messagebox("Please confirm", 4,"Batch Number")
If answer% = 6 Then
While Not (doc Is Nothing)
If doc.PStatus(0) = "Active" Then
'--create new copy document--'
Set newdoc = doc.CopyToDatabase (db)
newdoc.DocumentId = doc.UniversalID
newdoc.PBatchNo = dialogDoc.BBatchNo(0)
Call newdoc.Save(True, False)
'-- set new acceptance form --'
Set repdoc = New NotesDocument (db)
repdoc.Form = "EmpPCSpec"
repdoc.ABatchNo = doc.PBatchNo(0)
repdoc.AStatus = doc.PStatus(0)
repdoc.ATagNo = doc.PTagNo(0)
repdoc.AFStatus = doc.PFStatus(0)
repdoc.AInspector = dialogDoc.BInspector(0)
repdoc.AStart = dialogDoc.BStart(0)
repdoc.AEnd = dialogDoc.Bend(0)
Call repdoc.ReplaceItemValue("AStatus", "Incomplete")
Call repdoc.ComputeWithForm(False,False)
Call repdoc.save(True,False)
doc.PStatus = "Lock"
Call doc.ComputeWithForm(False,False)
Call doc.save(True,False)
End If
Set doc = view.GetNextDocument(doc)
Wend
End If
End If
All this process I run on one button. So when I run this button, I have success to create new batch info, I can create copy of document, and I can create report document.
But the problem now are in copy document, it did not display BBatchNo. And in report document, it did not display BInspector, BStart, and BEnd that I want to get from PCBatchInfo form. The field left empty. I hope my explaination is clear about my problem. Any help from you guys I appreciated. Thanks!
Update Question
For all information save for new batch info using PCBatchInfo, the view is on (PCBatch). How can I get the value in this view? I only get value from "Computer" where it save Computer document.
I think your problem is right here
Set dialogDoc = New NotesDocument(db)
You carefully got the document object from the current UIDoc and then overwrote it with a new (blank) document.
I'm trying to generate document links from another form using a button I created (in pass through below). Upon clicking the button, an agent must run and document link/s should be generated, and the current form should still be in edit mode (web).
Here are the issues:
1. I am unable to generate document link/s coming from another form through the view. The key is PeopleID, the current document has the computed field which should match with another form.
2. When I click on the button, it redirects me to the agent page and says that the agent is done running (non-verbatim). It should still be on the current document (current page, only that the document link/s should be generated).
Below is the code I use on the form (in pass-through) for the button and JS function to run agent.
<input type="button" value="Generate Link" onclick="javascript:runAgent();">
<script language="JavaScript">
function runAgent() {
var path = document.forms[0].BaseLink.value; // BaseLink is the prefix url.
var completeUrl = path + '(GenerateDoc)?OpenAgent&UNID=' + document.forms[0].UniqueID.value;
self.location.href = completeUrl;
}
</script>
After this, I have a rich text field named "DocumentLink", computed.
For the agent code, here it is:
Dim session As New NotesSession
Dim db as NotesDatabase
Dim curDoc as NotesDocument
Dim difDoc as NotesDocument
Dim view as NotesView
Dim rtitem as NotesRichTextItem
Dim peopleID as String
Set db = session.currentDatabase
thisDocumentID = Right$(session.DocumentContext.query_string(0),32)
Set curDoc = db.GetDocumentByUNID(thisDocumentID) //For some reason I am not getting anything here.
Set view = db.GetView("MyView")
peopleID = curDoc.PeopleID(0)
Set difDoc = view.GetDOcumentByKey(peopleID,true)
If Not difDoc Is Nothing Then
Set rtitem = curDOc.GetFirstItem("DocumentLink")
rtitem.values = ""
Call rtitem.AppendDocLink(difDoc,"Link to other form")
Call curDoc.Save(True,False)
End If
Appreciate your help.
There are several issues with what you are doing.
First: The self.location.href = completeUrl; line in Javascript will redirect the browser to the agent which has no relationship to the currently selected or open document. Alternatives to this approach would be using AJAX techniques from jQuery or other framework to run your agent asynchronously. If you have not saved the current document then there might not be a UNID on the Query String using your current approach.
Second: You should put the PeopleId on the query string also so that the agent can read it. The agent should then parse the Query_String_Decoded to get the two elements UNID and PeopleId.
Third: your agent is not generating any output. You should use PRINT statements in the LotusSctipt to create some feedback. You can also create JavaScript Tags and calls to calls to redirect back to the original page/document.
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 )
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)