« My Life Is Battery Powered, But What To Do With The Dead Units? | Main| When It Comes To The Top 1000 Corporate Web Servers, Domino is #4 »

Domino Web Tip – The Forgotten $$SelectDoc Field

Category Programming
In the view properties dialog there is a choice to “Allow Selection of Documents,” which will generate a checkbox for each document as viewed by a browser. This feature precedes the ND6 release, but the documentation is nearly mute on explaining how to use this feature. In a conversation with a new Domino web developer, I realized that she needed more information about how it worked. Here’s the short explanation: each checkbox is associated with a Domino created $$SelectDoc field with the document’s unique ID as the field value.

Here are a couple of ideas of how to use it:


By viewing the html source, we can see the structure of the checkbox. It’s an input object with a property of “checkbox” and a value of the document unique ID. It’s a nice feature of Notes to provide this view property for web developers, but anyone could have just as easily have created the same feature with a simple column formula. That’s why I find the minimal documentation puzzling—obviously, the “selection” option is to assist new Domino web programmers. So, it seems odd that it is weakly documented.

Once a view is generated with the checkbox option, then it is time to harvest the checked values. You’ll want to add a little JavaScript to gather up the document unique IDs for each selected document and add this information to a URL.

var docs= document.forms[0].$$SelectDoc;
var itemchecked = false;
var unid = "";
for (index=0; index<interests.length; index++)
{
if(docs[index].checked)
{itemchecked=true);
if(unid==""){unid="&"+docs[index].value}
else{unid=unid+"&"+docs[index].value}
}
}
if(! itemchecked){alert("you better have checked something")}
else {location.href = "/mydatabase.nsf/myagent?OpenAgent"+unid}


You have two basic choices: run the unique IDs through an agent, or have a form or page present the data. The advantage of an agent is that you have complete control. The advantage of a page or form is that you don’t have to dwelve into LotusScript or Java.

Here is a sample agent:

Sub Initialize
Dim session As New NotesSession
Dim db As NotesDatabase
Dim doc As NotesDocument
Dim viewdoc As NotesDocument
Dim counter As Byte
Set db = session.CurrentDatabase
Set doc = session.DocumentContext
formData = Split(doc.Query_String_Decoded(0), "&")

Forall x In formdata
Print x + "<br>"
If x = "OpenAgent" Then
'Do nothing
Else
Set viewdoc = db.GetDocumentByUNID(x)
Print viewdoc.booktitle(0) + "<br>"
End If
End Forall
End Sub


I’m using the new ‘split’ LotusScript function to slice up the returned URL argument, whereby I now I have the document unique ID for each selected row of the view, and now I can find the document.

But, I don’t always have to step into LotusScript or Java to return the selected values of a web query. Other than the $$Return field, there hasn't been a method to generate a reponse to a URL request except through LotusScript and Java agents with their print and println functions. ND6 adds the @URLQueryString which can be used to manipulate the retrieved values and display the results on a page (computed text) or a form.

Some developers have lamented that there is a limit to how many documents can be selected. This is because each $$SelectDoc entry that is checked adds another 33 characters to the URL (32 for the UNID and a 33rd for the "&" separator). It's possible to check so many documents that the default URL length is exceeded. If this is a problem, then don't use the built in "Select Document" view property and make your own. In the column you want the checkbox to appear create the pass-thru HTML for creating an input object with a "checkbox" type and make the value equal to the document ID. The document ID is an eight character tag that is unique to the specific database in which the document exists. Now you can select four times as many entries. It also means that the document ID method will not work between replicas, so as long as you are not building a web application that is clustered with multiple servers, then your application will work just as well.

So, by using the “select document” view propery, it’s very straightforward to create an application whereby the selected values are appended to an URL and then processed by a LotusScript/Java agent or even presented through a page or form.

Comments

Gravatar Image3 - Amended again
----------------------------


var docs = document.forms[0].$$SelectDoc;
var itemchecked = false;
var unid = "";
for (index = 0; index < docs.length; index++) {
if (docs[index].checked) {
itemchecked = true;
if (unid == "") {
unid = "&" + docs[index].value
}
else {
unid = unid + "&" + docs[index].value
}
}
}
if (!itemchecked) {
alert("you better have checked something")
}
else {
location.href = "/mydatabase.nsf/myagent?OpenAgent" + unid
}

Gravatar Image2 - Fix Code

var docs = document.forms[0].$$SelectDoc;
var itemchecked = false;
var unid = "";
for (index = 0; index < interests.length; index++) {
if (docs[index].checked) {
itemchecked = true;
if (unid == "") {
unid = "&" + docs[index].value
}
else {
unid = unid + "&" + docs[index].value
}
}
}
if (!itemchecked) {
alert("you better have checked something")
}
else {
location.href = "/mydatabase.nsf/myagent?OpenAgent" + unid
}

Gravatar Image1 - Thanks Jack

It is very usuful....

Post A Comment

:-D:-o:-p:-x:-(:-):-\:angry::cool::cry::emb::grin::huh::laugh::rolleyes:;-)