How to save agent output in a Web-based application

In my CRM application I wanted users to use client information in other applications, where they must be able to download specific information from the database, such as e-mail addresses. Here's how I did it.

Create a form with a embedded view for the web
($$ViewTemplate for <viewname>)
with a field called $$SelectDoc (hidden for Web)
and a field SaveOptions with value "0" 
to prevent saving of the document.

On the associated view-properties under the 
advanced tab 'Allow selection of documents
' has to be checked.

WebQuerySave event calls the agent.

What happens is that the File Download box appears.
When you select Open, a text file 
opens with all e-mail addresses of the selected documents.

The trick is the lines
Print ("Content-type: application/txt");
Print ("Content-Disposition: attachment; filename=test.txt");

These send HTTP-Header information. 
  Code: code for action on actionbar on view:
var cb = document.forms[0].$$SelectDoc;
//find the first checked document ..
var selectcount = 0;
var docUNID = new Array();
for (i = 0; i < cb.length; i++) {
     if (cb[i].checked) {
          docUNID[selectcount] = cb[i].value;
if  (docUNID[0] == null) {
  alert('No documents selected.');
  if (docUNID != null){
         result = window.confirm('Emailaddresses
 are exported. Select OK to confirm');
         if (result == true){

The submit statement triggers the WebQuerySave event.

agent (webGetEmailaAddresses):

Sub Initialize
Dim ses As New notessession
Dim db As notesdatabase 
Dim doc, newDoc As notesdocument
Dim item As notesitem
Dim dateTime As New  
Set db=ses.currentdatabase
Set doc = ses.DocumentContext
Set item = doc.getFirstItem("$$SelectDoc")
Print ("Content-type: application/txt");
 Print ("Content-Disposition: attachment; filename=test.txt");
'for every value $$SelectDoc
 get the notes-document Forall v In 
item.Values Set newDoc = 
'send the emailadress to the
 browser Print  newDoc.Email(0) & Chr(13)
End Forall
End Sub

Do you have comments on this tip? Let us know.

This tip was submitted to the SearchDomino.com tip exchange by member W Bergkamp. Please let others know how useful it is via the rating scale below. Do you have a useful Notes/Domino tip or code to share? Submit it to our monthly tip contest and you could win a prize and a spot in our Hall of Fame.

This was first published in April 2005

There are Comments. Add yours.

TIP: Want to include a code block in your comment? Use <pre> or <code> tags around the desired text. Ex: <code>insert code</code>

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy
Sort by: OldestNewest

Forgot Password?

No problem! Submit your e-mail address below. We'll send you an email containing your password.

Your password has been sent to:

Disclaimer: Our Tips Exchange is a forum for you to share technical advice and expertise with your peers and to learn from other enterprise IT professionals. TechTarget provides the infrastructure to facilitate this sharing of information. However, we cannot guarantee the accuracy or validity of the material submitted. You agree that your use of the Ask The Expert services and your reliance on any questions, answers, information or other materials received through this Web site is at your own risk.