3

is there a way to run server side javascript periodically in lotus notes?

I try to create an java agent with this simple script

      ScriptEngineManager manager = new ScriptEngineManager();
      ScriptEngine engine = manager.getEngineByName("JavaScript");
      Bindings bindings = engine.createBindings();
      bindings.put("session", session);

      Object result = engine.eval("var v:NotesView = session.getCurrentDatabase().getView('allDocumentsByFormName');print(v.getTitle());"                 
        , 
      bindings);

      System.out.println(result);

but it doesn't work.

Do you have any suggestions?

Pudelduscher
  • 359
  • 3
  • 18

3 Answers3

3

Don't bother. Your best best is an XAgent that you either trigger using DOTs or through a scheduled agent that calls the URL.

stwissel
  • 20,110
  • 6
  • 54
  • 101
  • thanks, that sound good, but if i call the XAgent over `URL url = new URL("http://server/db.nsf/xAgent.xsp"); URLConnection conn = url.openConnection();` i have a login problem, because the agent must authenticated and sorry for the stupid question, but what is DOT? – Pudelduscher Jul 10 '12 at 11:28
  • Well, how were you expecting a periodic server-side agent to know what identity to use? – Richard Schwartz Jul 10 '12 at 15:45
  • If you write your XAgent not to use anything from the URL you could use sessionAsSigner instead of authentication. DOTS a.k.a [Tasklets](http://www.openntf.org/internal/home.nsf/project.xsp?action=openDocument&name=OSGI%20Tasklet%20Service%20for%20IBM%20Lotus%20Domino) on OpenNTF – stwissel Jul 10 '12 at 16:58
  • and you could use the Apache HTTP client and generate a session token from the server using the Java classes – stwissel Jul 10 '12 at 16:59
  • thanks a lot for these great tips, i think one of them will solve my problem. – Pudelduscher Jul 10 '12 at 18:08
2

Hmmm.... I do not think that is possible.

One major obstacle to this is that the XPages JVM and the agent manager JVM are not the same. This is why you cannot reuse a Java class (the new design element in 8.5.3) in an agent.

However, the code example you show could easily be coded as a "standard" Java agent just using Java. I know that the example may just be for demonstration purpose - but you have all the backend classes available in Java and therefore you may be able to code what you need in pure Java. It is stable, scalable - as long as you remember to recycle objects (as always in Java) ;-)

/John

John Dalsgaard
  • 2,797
  • 1
  • 14
  • 26
0

I'd suggest writing a scheduled agent in LotusScript instead. I know the syntax might be unfamiliar, but it's an awful lot easier to do something natively than shoe-horning it.

David Navarre
  • 1,022
  • 10
  • 27