Preventing duplicate entries

Good Morning,

I am currently trying to write some LotusScript in my forms querysave to prevent duplicate entries. Here is the situation:

I have 5 fields

  1. First Name

  2. Last Name

  3. Start Date

  4. End Date

  5. Duty Status

I am trying to make sure the user does not input a troopers daily information twice. However, A trooper can work more than once on the same day, but he would always have to have a different Duty Status.

Here is what I am doing so far, any suggestions would be appreciated.

First I initialize the fields, then I set some variables:

Dim docStatus As String

docStatus = uidoc.FieldGetText( “DutyStat” )

I do this for the 5 fields.

So then I created a view to capture daily input and so this script can check against it for duplicate entries.

Set view = db.GetView( “DuplicateChecker” )

Set dc = view.GetAllEntriesByKey( docStatus, True)

I am just gonna check duty statuses and compare the first and last name, start date and end date.

If dc.Count = 0 Then

	Exit Sub	

Else

If it doesn’t find anything it will just exit, but here is where it gets hazy for me, how do I check the other 4 entries in my view against what is currently being input. That is, if the duty status is the same, and so is the start date, end date, first name and last name, I need to kick out an error message saying that this could be a duplicate entry, please make sure the duty status is correct, or make sure you are not inputting duplicate information.

any help would be appreciated.

thanks,

stephen

Subject: preventing duplicate entries

  1. Create categorize view by FirstName+LastName2. In your QuerySave use GetAllDocumentByKey(FirstName+LastName)

  2. Loop for all document you got.

  3. Check if field value 1…5 is equal to field value 1…5. It’s your call what field you want to compare.

  4. If equal then check if UniversalID is equal

  5. If equal it means it only editing the existing file. It’s up to you if this error or not.

  6. If not then “error possible duplicate copy.”

  7. process next document (go to step 4.)

Give it a try!

Subject: RE: preventing duplicate entries

Thanks Dong,

I see what you are saying, and I am close, but how do I do step 3. I mean that is my big problem, I am not sure what code to use to check the data being input against the data captured in my view. I am still kind of novice with LotusScript. Any suggestions?

Thanks

Subject: RE: preventing duplicate entries

for step 3:

Dim tempDoc As NotesDocument

Dim v As notesview

Set v = db.GetView(“”)

Set tempDoc = v.GetFirstDocument

While Not tempdoc Is Nothing

<your code here>



Set tempDoc = v.GetNextDocument

Wend

Subject: RE: preventing duplicate entries

Ok Thanks for step 3,

How about step 4, how would I check what is currently being input against what is already in the view. I imagine it would be some sort of getentrybyKey, or getallentriesbyKey, but how do I compare them?

any help would be great.

Subject: RE: preventing duplicate entries

Hope this will help or give you an idea…

Dim session As New NotesSession

Dim thisDB As NotesDatabase

Dim troopersView As NotesView

Dim troopersDoc As NotesDocument

Dim doc As NotesDocument

Dim workspace As New NotesUIWorkspace

Dim uidoc As NotesUIDocument

Dim colDocCollection As NotesDocumentCollection

Dim isCreated As Integer

Set thisDB = session.CurrentDatabase

Set uidoc = workspace.CurrentDocument

If uidoc.IsNewDoc Then

Set doc = uidoc.document

Set troopersView = GetView(thisDb, “DuplicateChecker”, True)

Set colDocCollection = troopersView.GetAllDocumentsByKey(doc.FirstName(0)+doc.LastName(0), True)

Set troopersDoc=colDocCollection.GetFirstDocument

Do While Not(troopersDoc Is Nothing)

 If (doc.DutyStatus(0)=troopersDoc.DutyStatus(0) And doc.FirstName(0)=troopersDoc.FirstName(0) And doc.LastName(0)=troopersDoc.LastName(0)) And (doc.UniversalID <>troopersDoc.UniversalID)Then

      isCreated = 1

      Exit Do		

 End If

 Set troopersDoc=colDocCollection.GetNextDocument(troopersDoc)			

 Loop	

If isCreated Then

 Messagebox "Document cannot be save duplicate entry!"

Else

 Messagebox "No duplicate entry you can save your document!"

End If

Else

Messagebox _

( "No need to check, this is existing document" )

End if