Process selected documents on the web (v1)

The code below will loop thru all the selected documents in a web view (embedded or standard). (1) Verifies than documents have actually been selected and prompts the user if none have been. (2) Prompts the user with an OK/Cancel window if the wish to proceed. (3) Loops thru the collection and only processes unique documents (helpful if you have the same document shown multiple times when showing multiple values as seperate entries). (4) For each unique document, the code launches an agent in the "AFrame" frame and passes the selected documents UNID variable via the URL. (5) The code will shortly pause after each call to the agent to allow process time. (6) Finally, the code refreshes the agent frame to blank and reloads itself.
JavaScript • Lotus Notes View • LotusScript

JAVASCRIPT BUTTON

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('You did not select any documents, please correct and try again.');
} else {
	if (docUNID != null ){
		result=window.confirm('Publishing will send an email for each selected document, click OK if you wish to proceed.');
		if (result==true) {
			var lastunid = ''
			for(j = 0; j < docUNID.length; j++){
				if ( docUNID[j] == lastunid) {
					//do nothing, the current doc has already been processed during this cycle
				}
				else {
					lastunid = docUNID[j]
					parent.AFrame.location.href = document.forms[0].dbURL.value + "/Publish?OpenAgent&docunid=" + docUNID[j]
					for (d=0;d<20000;d++) ; // do nothing but eat CPU
				}		
			}
			lastunid = ''
			parent.AFrame.location.href = document.forms[0].dbURL.value + "/Blank?OpenPage"
			self.location.href = document.forms[0].dbURL.value + "/PPEdit?OpenForm"
		}
	}
}

PROCESS AGENT CODE

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 ; 18)", doc)
	Dim docUNID As String
	docUNID = qstring(0)
	
	'Get a handle on the parent document
	Dim pdoc As NotesDocument
	Set pdoc = db.GetDocumentByUNID( docUNID )
	
	If Not pdoc.published(0) = "Yes" Then
		pdoc.Published = "Yes"
		Call pdoc.save(True, True)
		
		Dim edoc As notesdocument
		Set edoc = db.createdocument
		edoc.Form = "Memo"
		edoc.SendTo = "person@domain.com"
		edoc.Subject = "Payment: " & pdoc.ControlID(0)
		
		Dim rtitem As notesrichtextitem
		Set rtItem = edoc.CreateRichTextItem("Body")
		Call rtitem.AppendText("To whom it may concern,")
		Call rtitem.Addnewline(2)
		Call rtitem.AppendText("Email message line #1" )
		Call rtitem.Addnewline(2)
		Call rtitem.AppendText("Email message line #2" )
		Call rtitem.Addnewline(2)
		Call edoc.Send(False)
		
	End If
	
End Sub

Posted by fbrefere001 on Friday March 21, 2003