Capture PRINT statements to reuse LS Agent in XPages - Part 3/3


function agentResult(agentName) {
    var doc = database.createDocument();
    var agent = database.getAgent(agentName);

    // Here is the run
    try {
        agent.runWithDocumentContext(doc);
    } catch(e) {
        return e.message;
    }   
    var out = session.createStream();
    var mimeEntry = doc.getMIMEEntity("AgentPrintOutputResult");
    mimeEntry.getContentAsText(out);
    out.setPosition(0);
    var result = out.readText();

    //Cleanup
    mimeEntry.recycle();
    doc.recycle();
    out.recycle();
    agent.recycle();

    return result;
}
All code submitted to OpenNTF XSnippets, whether submitted as a "Snippet" or in the body of a Comment, is provided under the Apache License Version 2.0. See Terms of Use for full details.
No comments yetLogin first to comment...