Question: When upgrading classic Domino applications to XPages one particular problem arises constantly: "what to do with the PRINT statements in existing agents that write back directly to the browser?" I have 200 agents in my nsf file which all uses Print statement in their code.
I have investigated found the link <http://www.wissel.net/blog/d6plinks/SHWL-8SF7AH>
but it is not possible for me to change agent code as it is also used from forms.
I have to re-use these agents from xpages on button click and also have to pass document.
Is there any way or alternative which can solve my problem.
help is required.

We have Agent.runWithDocumentContext(doc:NotesDocument) method which can run the agent from xpage and passing an in-memory document. I create an im-memory document

```
   var doc = database.createDocument();
   doc.replaceItemValue("StartDate",startDate.getDateOnly())
   doc.replaceItemValue("EndDate",endDate.getDateOnly())
   doc.replaceItemValue("ReportName",reportName)
    var agent:NotesAgent = database.getAgent("("+reportName+")");

    agent.runWithDocumentContext(doc);   

```

This in-memory document i can pass to the agent. But the issue I am facing currently that my agents are used to print directly which is not possible through xpage i assume.
Is there any alternative way to pass in-memory document to agent and able to print directly to browser through xpages.
Help needed please help.

Answer: 
If you want to use XPages.. then USE XPages... Meaning migrate the agents to the XPages way of doing things. There can be a lot of coexhistance between XPages and Notes Client or I supposed even Classic Domino Web. But if you're set on keeping 200 Agents which are NOT really part of XPages Best practices, then it sounds to me like you shouldn't be using XPages at all.

EDIT: 
This link:
<http://www-10.lotus.com/ldd/ddwiki.nsf/dx/XPages_and_Calling_Agents_Using_an_In-Memory_Document>

Talks about calling an Agent from XPages and being able to use the in memory document. Maybe that will help but if it's heavily used performance will not be great since an agent loads and unloads for each call. It's still a bad idea to do.
create a java class that calls your agent and read the output from your agents in an input stream and display the stream in computed field in Xpages. 

here is a sample java class that will retrive the output from your agent

```
package com.thomas;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.MalformedURLException;
import java.net.URL;

    public class getAgentData{

        public String getData() throws IOException {
            try {
                URL url = new URL("http://localhost/mydatabase.nsf/myagent?openagent");

                BufferedReader in = new BufferedReader(
                new InputStreamReader(url.openStream()));
                String content = new String();
                String inputLine;
                while ((inputLine = in.readLine()) != null) {
                    content+=inputLine;
                }
                in.close();
                return content;

            } catch (MalformedURLException e) {
                e.printStackTrace();
            }
            return null;
        }
    }

```

If you add your java class as a bean in faces-config.xml you can call it using a computed field in your xpages like this 

```
<xp:text escape="true" id="computedField1" value="#{javascript:getAgentData().getData()}"></xp:text>

```