Process selected documents in web view via back-end agent.

The steps below outline how to process the selected documents of a view. Normally, the selected documents option is used for deletion of documents where a simple action button with the formulas @Command(MoveToTrash) & @Command(EmptyTrash) will do the trick, but allowing the user to perform much more complex functions on the selected documents requires much more. Embedded views in Domino create a (on-the-fly) multi-valued field called $$SelectDoc, which contains all the DocumentUniqueID's of the selected documents. However, the values of this field are only transferred to a physical notes field when the document is saved by using a javascript submit button. Using @Command(FileSave) will not populate the values.
HTML • Lotus Formula • Lotus Notes View • LotusScript

Here's the actual text to copy & paste for the Process action hotspot

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('You are going to process the selected documents, click OK if you wish to proceed.');
		if (result==true) {
			document.forms[0].SelectedDocs.value = docUNID
			document.forms[0].submit();
		}
	}
}

Here's the actual code to copy & paste for the agent below in Step F

Sub Initialize

Dim session As New notessession
Dim db As notesdatabase
Set db = session.currentdatabase
Dim doc As notesdocument
Set doc = session.DocumentContext

Dim pdoc As NotesDocument
Dim edoc As notesdocument

'Loop through all the selected document UNID's contained in the SelectedDocs field
For x = 0 To Ubound(doc.SelectedDocs)
'Get a handle on the selected document by its DocumentUniqueID
Set pdoc = db.GetDocumentByUNID( doc.SelectedDocs(x) )
'Create a dummy document for each of the selected documents
Set edoc = db.createdocument
edoc.Form = "TESTFORM" 
edoc.ControlID = pdoc.ControlID(0)
Call edoc.save(True, True)
Next

End Sub

Images/Screenshots:









Posted by fbrefere001 on Thursday March 27, 2003