I have a form and a action on it, the form should run on the web.
the action has the following code:
@Command([FileSave])
So I guess she should triger the agent that is refernced per WebQuerySave.
Here is the code in WebQuerySave:
@Command([ToolsRunMacro]; “Cnm”)
“Cnm” is the name of the agent as it stands in his properties although I have changed it for a while with “(Cnm)” not in the properties but in the reference in the WQS. And it worked that confused me.
Nothing, realy nothing happens when i click the action the browser remains as it is.
When i use a button on the form with this javascript code:
document.forms[0].submit();
I get a new page with the message Form processed.
Please help me
Here is the code that is in the agent:
Sub Initialize
Dim s As New notessession
Dim db As notesdatabase
Dim vw As notesview
Dim curdoc As notesdocument
Dim vwdoc As notesdocument
Dim brojugovora As String
Dim username As String
Dim password As String
Set db = s.GetDatabase("HERMES/pincom","pdm.nsf")
If db Is Nothing Then
Print "<H1>Nemogu otvoriti bazu!</H1>"
Exit Sub
End If
Print "<H1> Show something </H1>"
Set vw = db.getview("WICRnlg")
If vw Is Nothing Then
Print "<H1>"Nemogu pristupiti radnim nalozima" </H1>"
Exit Sub
End If
Print "<H1>Nemogu otvoriti bazu!</H1>"
Set curdoc = s.DocumentContext
Print "<H2>" + doc.Subject(0) + "</H2>"
If curdoc.BrjRnlg(0) = "" Then Exit Sub
Set vwdoc = vw.getdocumentbykey(curdoc.BrjRnlg(0))
If vwdoc Is Nothing Then
Print "<H1>Nemogu pronaci radni nalog s tim brojem</H1>"
Exit Sub
End If
Print "<p>" + vwdoc.doc_broj(0) + "</p>"
When testing a webquerysave agent, I usually use an errorroutine that writes the linenumber to the browser if something goes wrong, so I know where to look and you don’t get the Form processed warning:
Sub Initialize
On error goto errorRoutine
…
…
Print “
” + vwdoc.doc_broj(0) + “
”
exit sub
errorRoutine:
Print "Error on line " +cstr(Erl())
Exit sub
End sub
When the agent works fine I dim/remove the errorhandling, since I don’t want the user to be bothered by lines that means nothing to them.
You can normally not open other servers from your agents unless the server is set as trusted in server document. You are probably getting error in line Set db = s.GetDatabase(“HERMES/pincom”,“pdm.nsf”)
I don’t exactly know what you mean by “the designated frameset from the database opens”.
It looks like your agent still doesn’t work?
Another option (I don’t know if it is possible for you to do) is to create a replica of pdm.nsf on the same server as where the agent runs. In that case you shouldn’t worry about trusted servers, etc.
When you are developing Web Query agents, it helps a lot to have access to the server console, or at least the log.nsf. Always when there is a security configuration problem, or an error, it will display there.
You can force messages to both the console, and the log by using msgbox “something” inside your code. If you are unsure if your agent is running at all, remove (or comment out) all code, and just leave a single msgbox, if it displays, you know your code is running…
I took the liberty to rewrite your code a bit, it should work now. (The comment about accessing servers that are not local still applies, and you need to set up a trust if you need this. Easier is to try to get a local replica of the lookupdatabase to your server, and it should be quicker too…)
Sub Initialize
Dim s As New notessession
Dim db As New notesdatabase("", "") '// declare it empty, so we can change it later
Dim vw As notesview
Dim curdoc As notesdocument
Dim vwdoc As notesdocument
Msgbox "if you see this in the server log/console, I am running!"
On Error Goto errorhandler
'// i use this method to get a database, since it ALWAYS returns a db, open or not
Set db = New NotesDatabase("HERMES/pincom","pdm.nsf")
If db.IsOpen Then
Print "<H1> Show something </H1>"
Set vw = db.getview("WICRnlg")
If Not vw Is Nothing Then
Print "<H1>Nemogu otvoriti bazu!</H1>"
Set curdoc = s.DocumentContext
Print "<H2>" + curdoc.Subject(0) + "</H2>"
'// if BrjRnlg is blank, you should find no document, so no real need to test for it
Set vwdoc = vw.getdocumentbykey(curdoc.GetItemValue("BrjRnlg")(0), True) '// always use true, unless you know you wont need it
If(Not vwdoc Is Nothing)Then
Print "<p>" + vwdoc.GetItemValue("doc_broj")(0) + "</p>"
Else
Error 1003, "Nemogu pronaci radni nalog s tim brojem"
End If
Else
'// view is nothing throw an error and exit
Error 1002, "Nemogu pristupiti radnim nalozima"
End If
Else
'// throw an error and exit
Error 1001, "Nemogu otvoriti bazu!"
End If
die:
Exit Sub
errorhandler:
'// just print the error and exit cleanly
Print |<h1>Error "| & Error & |" happened on line: | & Erl & |</h1>|
Resume die
thank you for your answer. I Have created a new agent from your code and it opens the whatever is set up by the launch option of the database (“Launch as last viewed by user”, “Launch designated frameset” etc.).
I also have included a piese of code from Rene that tests if the database is open and it returns No Access.
I will try tu set the server as trusted and i hope it will work