Domino Code Fragment

Code Name*
Checking for Pre-Existing Documents
Date*
04/28/2024
Source (or email address if you prefer)*
Rlatulippe@romac.com
IP address:.3.137.221.163
Description*
Type*
Formula
Categories*
(Misc)
Implementation:
Required Client:
Server:
Limitations:
Comments:
Files/Graphics attachments (if applicable): Code:
Problem:

When composing new documents, the customer wants to be able to click on a button, and check for documents with the same Social Security Number as the newly created document. If a document already exists, they should discard the new document, and edit the old document. Otherwise, they should continue composing this new document.

Solution:

Make two Forms called "Social Security Number" and "(Social Security Number) | Social Security Number"
Make a View called "SSNumber"
Make a Background Macro called "Delete"


The first Form will be used to compose new documents, and the second will be used to edit and read already existing documents (see the Form Formula at the bottom of this technote). The two Forms will be identical, except that the first will have some static text and a button which the second Form will not have.

SSNumber is a field for the Social Security Number. I would recommend some sort of validation formula, to ensure consistent entering of the number, such as:
@If(@Matches(SSNumber; "{0-9}{0-9}{0-9}-{0-9}{0-9}-{0-9}{0-9}{0-9}{0-9}"); @Success;
@Failure("You must type in the Social Security Number in the format \"nnn-nn-nnnn\""))

DeleteMe is a field used to flag the duplicate documents for deletion. This field will be hidden,
and computed. Its formula will simply be:
DeleteMe


Static Text (only for the first Form):
Click on the button to check for pre-existing Social Security Numbers. If this is a unique occurrence, it will put up a dialog box informing you of this fact. You may then continue entering data. If this is a duplicate occurrence, it will delete this record, and put you into edit mode in the already existing document. You may then continue entering data.

Button Formula (only for the first Form):
SocialSecurityNumber := SSNumber;
X := @DbLookup("Notes" : "NoCache"; ""; "SSNumber"; SSNumber; "SSNumber");
FIELD DeleteMe := "1";
@If(!@IsNewDoc; @Prompt([OK]; "Error"; "Only press this button on new documents. Thank you.");

!@Matches(SSNumber; "{0-9}{0-9}{0-9}-{0-9}{0-9}-{0-9}{0-9}{0-9}{0-9}");
@Prompt([OK]; "Error"; "You must type in the Social Security Number in the format \"nnn-nn-nnnn\"");
@IsError(X); @Do(@SetField("DeleteMe"; "0");
@Prompt([OK]; "Social Security Number Not Found!";
"You may continue composing this new Social Security Number Form"); @Command([EditDown]));
@Do(@Command([FileSave]); @Command([FileCloseWindow]);
@Command([OpenView]; "SSNumber"; SocialSecurityNumber); @Command([EditDocument]; "1");
@Command([EditDown])))

The View Selection Formula:
SELECT DeleteMe != "1"

The View Form Formula:
@If(@IsNewDoc; "Social Security Number"; "(Social Security Number)")

The Background Macro should be set to run on the Server which holds the database, nightly:
@If(DeleteMe = "1"; @DeleteDocument; "");
SELECT @All