Situation:
A Computed <a href...> defines to open document or when is does not exists to create a new document.
Problem:
When new doc is created and link has not been refreshed, the user could create a double entry.
I ran into situation where only one comment is allowed per field on a form.
Solution:
An webqueryload agent checks if the document already exists and if so, it fills a field in the new document with the reference to the existing (new) form.
The Onload event of that form checks if the reference exists and if so, it changes the contents to the existing form.
This way you can prevent a user from submitting a new form twice.
Be careful, the page header must contain expire info.
This way you prevent that a double entry is made ( Although a webquerysave agent should doublecheck the save also)
Code
*****************
Main Form
*****************
'HTML Header
"<script type='text/javascript'>"+@NewLine+
"function openwindow(site)"+@NewLine+
"{"+@NewLine+
"window.open(site,'my_new_window',"+
"'toolbar=no,location=no,directories=no,"+
"status=no,menubar=no,scrollbars=no,resizable=no,copyhistory=no,width=460,height=340')"+@NewLine+
"}"+@NewLine+
"</script>"+@NewLine
'Computed Href
Fnm:="MyComment";
@If(!@IsNewDoc;
@If(!@IsError(@DbLookup("";"";"C1";@Text(@DocumentUniqueID)
Fnm;2));
"<a href='Javascript:{openwindow("+@Char(34)+"/" +@ReplaceSubstring(@Subset(@DbName;-1);"";"/")+"/2dd262338b8f9919c1256ac500360c84/"+@DbLookup("";"";"C1";@Text(@DocumentUniqueID)+Fnm;2)+"?OpenDocument"+@Char(34)+")}'><IMG SRC='/icons/vwicn005' Border=0></a><br>";
@If(@IsDocBeingEdited = 1;"<a href='Javascript:{openwindow("+@Char(34)+"/" +@ReplaceSubstring(@Subset(@DbName;-1);"";"/")+"/frmComment?OpenForm&ParentUNID="+@Text(@DocumentUniqueID)+ "&"
+Fnm+@Char(34)+")}'><IMG SRC='/icons/vwdrafts.gif' Border=0></A>";" ") )
;"")
************************
Comment/New form ( response )
*************************
'Prevent that browser uses cached form
HTML Head Content:
"<meta http-equiv='expires' content='Tue, 04 Dec 1993
21:29:02 GMT'>"
WebQueryOpen:
@Command([ToolsRunMacro]; "QSWebCommentOpen")
Onload:
var f = document.forms[0];
if (typeof f != "undefined")
{
if ( f.Exists.value=="99") {
location=f.OrgLink.value+"?Opendocument";
}
}
*******************
Agent used
******************
%REM
This agent checks during load if a response form
for the specific field already exists.
Since Notes Ignores a print comments, a value is set
on the form itself then the load event acts on this
value. You cannot use hide section stuff, cause the
HTML is already there.
%ENDREM
Dim currentDoc As CurrentWebDocument
Dim db As NotesDatabase
Dim viewValidation As NotesView
Dim ValidationCollection As NotesDocumentCollection
Dim WdocPath As Variant
Dim docValidation As NotesDocument
Dim RespID,NRespID As String
Set currentDoc = New CurrentWebDocument("")
WdocPath = currentdoc.doc.getitemvalue("zzDBPath")
Set db=currentdoc.doc.Parentdatabase
dbserver = db.server
If Dbserver = "" Then
dbserver = "LocalHost"
Else
DbServer = Mid(dbserver,Instr(dbserver,"=")+1)
DbServer = Left(dbserver,Instr(dbserver,"/")-1)
End If
RespId = currentdoc.doc.query_string(0)
RespId = Mid(RespId,Instr(RespID,"=")+1)
NRespId = Left(RespId,Instr(RespID,"&")-1)
NRespId = NRespID+Mid(RespId,Instr(RespID,"&")+1)
Set viewValidation=db.GetView("C1")
Set ValidationCollection = viewValidation.GetAllDocumentsByKey(NRespID ,False)
If ValidationCollection.Count <> 0 Then
Set docValidation=ValidationCollection.Getfirstdocument
currentdoc.doc.Exists= "99"
currentdoc.doc.OrgLink = "http://" +dbserver + "/"+WdocPath(0)+"/"+Cstr(viewvalidation.UniversalID)+"/" +Cstr(docvalidation.UniversalID)
Else
currentdoc.doc.Exists= "00"
End If
End Sub