Dual Web Action - Save/Post in formula & force file download save via bkgrd agent.

The example below was used in Global Data Collect. It performs four steps: (1) Sets the flag fields and download date (2) Saves/posts the document which refreshes in the browser to show the new status (3) OnSubmit checks which button was pressed and sends a URL to the browser (after the refresh) to download the file. (4) The background agent extracts the UNID from the URL string, gets a handle on the parent document, sends a print statement to the browser to force the open/save dialog box (otherwise PDFs would open in browser automatically), and finally sends the file URL to the browser to kick off the download.
Lotus Formula • Lotus Notes Form

JS HEADER

var xbutton = "None";








ONSUBMIT

if (window.navigator.appName == 'Lotus Notes') {
	//Notes Client - dont put anything in here
}
else {
	//web client
	if (xbutton == 'download') {
		//alert("download was pressed");
		parent.top.location.href= document.forms[0].dbURL.value + "/Download?OpenAgent&pdoc=" + document.forms[0].ur_ParentDocumentID.value
	}
	//reset global variable
	xbutton = "Done";
}

DOWNLOAD BUTTON

@If(
ur_status = "0" ;
@Do(
@SetField("ur_status" ; "1");
@SetField("ur_datedownloaded" ; @Now)
);
@Success) ;

@If(ur_adminlock = "Off" ; @Command([FileSave]) ; @Success)

DOWNLOAD AGENT

Sub Initialize
	
	Dim session As New notessession
	Dim db As notesdatabase
	Set db = session.currentdatabase
	Dim doc As notesdocument
	Set doc = session.DocumentContext
	
	'Get parentID from address variable
	Dim qstring As Variant
	qstring = Evaluate("@Rightback( Query_String ; 15)", doc)
	Dim ParentID As String
	ParentID = qstring(0)
	
	'Get a handle on the parent document
	Dim pdoc As NotesDocument
	Set pdoc = db.GetDocumentByUNID( ParentID )
	
	Dim URL As String
	URL = "/gdc/datacollect.nsf/files/" & pdoc.UniversalID & "/$File/" & pdoc.dr_attachmentname(0) & "?OpenElement"
	
	'Force the browser to download and pass the file URL
	Print "Content-Type:application/download"
	Print "Content-Disposition:attachment; filename=" & Chr(34) & pdoc.dr_attachmentname(0) & Chr(34)
	Print "[" + URL + "]"
	
End Sub

Images/Screenshots:

Posted by fbrefere001 on Monday February 24, 2003