A thought occurred to me yesterday. We all know you can run multiple WQS agents and that you can make them conditional using @If statements, right? What I didn't know was whether you could have two agents run but only have the second agent run depending on the outcome of the first. Imagine the code below:
In the example shown, does the server decide which agents to run and then just run them or does it run the first and then enter the @If to decide whether to run the second? That's what I didn't know. Well, it turns out it's the latter case. Agent One runs and sets a field on the document called "runSecondAgent" to a value of 1. This trigger Agent Two. If in Agent One you stop the code from setting that field value then Agent Two doesn't run. Just what I was hoping would happen.
Something I found out from testing this out is that you can't "print" to the browser from consecutive agents. Anything you print from the first is lost if a second agent runs. Even if that second agent doesn't print anything.
How did I end up wondering this in the first place?
It came about because I wanted to use the iText PDF library to create and send out an invoice once a document was saved. The Form already has a WSQ agent written in LotusScript. To generate the PDF I need to run some Java. Therein lied the problem. Depending on certain logic in the main LotusScript WQS agent I need to run some Java. The concept above solves this.
It's a bit of a messy solution though. Makes me wonder if there's isn't another way?
An Alternative, Which I'd Tried First, But Which Failed
I did all the usual LS2J stuff to create an object of the class called PDFInvoice, the code for which lived in a Java Code Library in the database and looked something like this:
It fails on line 8 though when you try and create a session object. Any reference to "s" after that returns a "null pointer".
Is there no way in LS2J to have the Java that's called operate on the current document (or any Notes objects for that matter)? As I understand it you can only pass primitive data-types as arguments. However, I was hoping to pass the document's ID over and somehow get to it that way. If I can't open a session though, how would that work?
I'm starting to wonder how good an idea it would be to just write all Agents in Java from now on. Seems to me there's little LotusScript can do that Java can't. Whereas the opposite is not true at all.