Prevent double entries

Prevent double entries

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)


*****************
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)

    Requires Free Membership to View

    Register today to access targeted resources from our editorial writers and independent industry experts focused on Lotus Domino, Notes, Workplace and other related technologies.

    By submitting your registration information to SearchDomino.com you agree to receive email communications from TechTarget and TechTarget partners. We encourage you to read our Privacy Policy which contains important disclosures about how we collect and use your registration and other information. If you reside outside of the United States, by submitting this registration information you consent to having your personal data transferred to and processed in the United States. Your use of SearchDomino.com is governed by our Terms of Use. You may contact us at webmaster@TechTarget.com.


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

This was first published in November 2001

Disclaimer: Our Tips Exchange is a forum for you to share technical advice and expertise with your peers and to learn from other enterprise IT professionals. TechTarget provides the infrastructure to facilitate this sharing of information. However, we cannot guarantee the accuracy or validity of the material submitted. You agree that your use of the Ask The Expert services and your reliance on any questions, answers, information or other materials received through this Web site is at your own risk.