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.
@Command([ToolsRunMacro];
"(webGetEmailAddresses)")
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;
selectcount++;
}
}
if (docUNID[0] == null) {
alert('No documents selected.');
}
else{
if (docUNID != null){
result = window.confirm('Emailaddresses
are exported. Select OK to confirm');
if (result == true){
document.forms[0].submit();
}
}
}
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 =
db.GetDocumentByUNID(v)
'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