Solved

Stopping duplicate entries

Posted on 2004-04-05
32
226 Views
Last Modified: 2013-12-18
Does anyone have the code I could use to stop a second user from completing a questionnaire for the same office. Let me break this down.
1. User in an office completes a form. There is a field for their office identity.
2. A second user from the same office who has also received a button to complete the form tries to complete the same form.
3. I know there is a way to setup a dbcolumn, or maybe dblookup and have the office identity field validate if a form has already been received for this office.
4. Lets the user know the form has already been recieved and closes them out of the form.

Thanks for the help in advance.
Joe
0
Comment
Question by:jforget1
  • 14
  • 10
  • 8
32 Comments
 
LVL 24

Assisted Solution

by:HemanthaKumar
HemanthaKumar earned 200 total points
ID: 10760219
Let us say you have a view already setup which lists requests by office (ReqByOfffice)

This code in QuerySave will block the save if the request already exists

dim s as New NotesSession
dim db as NotesDatabase
dim view as NotesView
dim doc as NotesDocument

set db = s.CurrentDatabase
set view = db.GetView( "ReqByOfffice")
set doc = view.GetDocumentByKey( Source.Document.OfficeID(0), True) ' I have assumed that OfficeId as the field which lists the name
If not doc is nothing then
 MsgBox "There is already a request that has been submitted by  " & doc.Requester(0) & " for this location"
Continue = false
End if

~Hemanth
0
 
LVL 46

Expert Comment

by:Sjef Bosman
ID: 10760234
This issue can almost be prevented in Notes, but never completely.

Assign one as manager, the other(s) as assistant, and let them communicate!
0
 

Author Comment

by:jforget1
ID: 10760240
Is there a way to have this validate when they leave the OfficeId field? I would hate to have them complete a long form only to have it tell them they wasted their time.
0
 
LVL 46

Expert Comment

by:Sjef Bosman
ID: 10760258
Hemantha, there should also be code in the QueryOpen of the form itself to prevent a lot of unnecessary work by #2. The document exists already (must be completed).

Assumption: Notes client??
0
 
LVL 46

Expert Comment

by:Sjef Bosman
ID: 10760263
Is the document already there and you ask them to complete a document, or are they creating a new document themselves?
0
 

Author Comment

by:jforget1
ID: 10760274
This order form may go to 4 people in the same office. Once one completes the form, anyone who enters the same office id I want it to tell them right away that it has been completed.
0
 
LVL 46

Expert Comment

by:Sjef Bosman
ID: 10760290
Cannot you create an empty document with the office id already filled in? And send the same document (not form) to all 4 people? Then you can easily block opening the document if the document is saved immediately when opened with a intermediary status.
0
 

Author Comment

by:jforget1
ID: 10760326
It would be harder to send a personalized form as now I send a button to all and do not have a list of where each person is in advance.
0
 

Author Comment

by:jforget1
ID: 10760389
Hemantha,

Could I add the code above to the exiting section of the field. Although I have the code below to validate the data entry.

Sub Exiting(Source As Field)
      Dim workspace As New NotesUIWorkspace    
      Dim session As New NotesSession    
      Dim uidoc As NotesUIDocument
      Set uidoc = workspace.CurrentDocument
      
      If Len(uidoc.FieldGetText("office_number")) <> 3 Then
            Messagebox "Parent Office ID must be exactly 3 characters long"
            Call uidoc.GotoField("office_num")
      End If
End Sub
0
 
LVL 46

Expert Comment

by:Sjef Bosman
ID: 10760403
No, not a personalized form, but do the following (if Hemantha agrees ;):
- when you know that a new document is to be create
- create the new document, with some fields filled in (status Initial)
- send a mail to the users with a button to edit the document (no create a new document)
- the first to open will change the status immediately (status Intermediate)
- if he escapes the document, status will be reset to Initial
- if he correctly finishes the document, status will be set to Completed

This will work except when the system crashes, so some provisions will have to be made for that, but otherwise nobody on the same server will be able to update the document. In R6 you can use document locking instead of a status, that's even more effective.
0
 
LVL 24

Expert Comment

by:HemanthaKumar
ID: 10760408
Yes you can use the same code in the queryopen, with little modification..so that they are cautioned ahead before they start making changes
0
 

Author Comment

by:jforget1
ID: 10760436
How could I add a dialog box which will prompt the user to enter an OffieId and then immediately validate against the completed view?
0
 
LVL 46

Expert Comment

by:Sjef Bosman
ID: 10760488
The question is yours, Hemantha... Over and Out.
0
 
LVL 24

Expert Comment

by:HemanthaKumar
ID: 10760531
For that you have to create a subform or form and call it in Postopen event as Dialogbox and use validation code above and abort accordingly.

This should be done in queryclose of the dialog box form
0
 

Author Comment

by:jforget1
ID: 10760840
I am close but still having a bit of trouble. I used the code below in a field. One issue that may be causing be problems here is the officeid is made up of 2 fields, office_num and a field called detached. I have a field that compbines these 2 fields called office_num_adjusted. I have the code in the exit of the detached field as I would not know the full office identity until they have entered into the detached field. What is strange, when I exit the detached field, it skips over the next 3 fields til it gets to another validation. Then I get a Notes Error - field did not pass validation. I know this is messy and I apologize.

Sub Exiting(Source As Field)
      Dim workspace As New NotesUIWorkspace    
      Dim session As New NotesSession    
      Dim uidoc As NotesUIDocument
      Dim agynum As String
      Set uidoc = workspace.CurrentDocument
      Set db = session.CurrentDatabase
      Set ndoc = uidoc.Document  
      
      Set view = db.GetView("(refreshcompleted)")
      Call uidoc.Save
      
      agynum = uidoc.FieldGetText( "office_num_adjusted")
      key = agynum
      Set ndoc = view.GetDocumentbyKey(key)
      If ndoc Is Nothing Then
            Exit Sub
      Else
            Msgbox "Thank you, but a survey has already been completed for your agency. "
            Set doc = uidoc.Document
            doc.SaveOptions = "0"
            Call uidoc.close
      End If
End Sub
0
 
LVL 24

Expert Comment

by:HemanthaKumar
ID: 10760986
If you have switched debuggger ON, close it and give it a try.
0
Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

 

Author Comment

by:jforget1
ID: 10765524
It is failing at the follwoing line. Is this because this field is a computed field combining the 2 pieces which make up the office id. THe exit script is on the second part, I wonder if the office_num_adjusted is not computed immediately upon exiting the detached field.

agynum = uidoc.FieldGetText( "office_num_adjusted")
0
 
LVL 24

Expert Comment

by:HemanthaKumar
ID: 10765720
then try this

agynum = uidoc.Document.Office_Num_Adjusted(0)
0
 

Author Comment

by:jforget1
ID: 10765857
I tried that and it fails at the same point.
0
 
LVL 24

Expert Comment

by:HemanthaKumar
ID: 10765969
try this.. if you believe that field hasn't computed properly

agynum = uidoc.DOcument.Office_Num(0) + uidoc.DOcument.Detacheda(0)
0
 

Author Comment

by:jforget1
ID: 10766136
I tried this and also changing uidoc to ndoc but I am still having no luck. I will double check everything to make sure it is not a gramatical error on my part.
0
 
LVL 24

Expert Comment

by:HemanthaKumar
ID: 10766191
In First place I discourage use of exit event for such a kind of validations..

I would suggest you to place a button next to Detached field ( and make this field computed) and execute Inbox method to collect detached field value. Then use the above code to validate for record's existence
0
 

Author Comment

by:jforget1
ID: 10766269
I am not sure what you mean by the inbox method, and when you say a button. Would the user have to click this to validate the field.
0
 
LVL 46

Expert Comment

by:Sjef Bosman
ID: 10766501
Did I insult you or didn't I take your problem seriously? If so, please accept my apologies. Or am I barking in the dark?

I'm still convinced that my approach could be a lot safer than the current one. Everybody seems to be allowed to enter new documents into the database. Is that true?

It only works of course if you can prepare a document with an office-id already filled in. You then supply the sessentials and they do the rest. The document should also contain an Authors-field, so nobody else can update the document. You shouldn't be dependent of the users creating a document, for a non-created document doesn't have a status because it doesn't exist. Turn everything around and your application will be a lot easier and the current status of documents can be shown in a view, even for the new documents.
0
 
LVL 24

Expert Comment

by:HemanthaKumar
ID: 10766550
Sorry it is not inbox method...I meant inputbox !

This will accept a value as prompt and insert it into detached field

eg:

ndoc.Detached = Inputbox( "prompt", "title")
0
 

Author Comment

by:jforget1
ID: 10766703
sjef, you did not insult me but having the office form filled out in advance is just not a viable option. This is being sent to over 300 offices and to find out where every person is located in near impossible I need this to validate once the user enters the information.
0
 

Author Comment

by:jforget1
ID: 10766732
I have been working with someone local and we are haing trouble with a type mismatch and have tried many version of the code. Here is the current which bombs with the same type mismatch error. The field in question is a text field. She is concerned about the uidoc vs. ndoc issue and we have tried many combination of this.

Sub Exiting(Source As Field)
      Dim workspace As New NotesUIWorkspace    
      Dim session As New NotesSession    
      Dim uidoc As NotesUIDocument
'      Dim ndoc As NotesDocument
'      Dim agynum As String
      Set uidoc = workspace.CurrentDocument
      Set db = session.CurrentDatabase
      Set ndoc = uidoc.Document
      
      Set view = db.GetView("(refreshcompleted)")
      
      a=Cstr(ndoc.office_number)
      b=Cstr(ndoc.detached)
'      agynum = Cstr(ndoc.office_number) + Cstr(ndoc.detached)
      agynum = a + b
      key = agynum
      Set ndoc = view.GetDocumentbyKey(key)
      If ndoc Is Nothing Then
            Exit Sub
      Else
            Msgbox "Thank you, but a survey has already been completed for your agency. "
            Set doc = uidoc.Document
            doc.SaveOptions = "0"
            Call uidoc.close
      End If
End Sub
0
 
LVL 46

Expert Comment

by:Sjef Bosman
ID: 10766798
So you rely heavily on the user typing in the correct OfficeId? Your NAB cannot be the source of information for you? Users do not have a certain role depending on their location? Or do not belong to a certain group depending on their location? How many documents are produced per office per day? If it's a small number, users won't mind to type in the number every time. Or do you already have a user profile document in the database?

Just a few hints to place everything in a broader perspective. The amount of offices should not worry you, it's a job for your Administrator to set it up, the names and groups or roles etc.
0
 

Author Comment

by:jforget1
ID: 10766845
I have validation in the fields which should eliminate them inputting incorrectly and due to the changing of office identities and user location I would not rely on the address book to be 100%
0
 
LVL 46

Accepted Solution

by:
Sjef Bosman earned 300 total points
ID: 10766850
If you use items from ndoc you have to know that they are all arrays! Mostly, attaching (0) will do if you only need the first element.

Just two examples:
     a=Cstr(ndoc.office_number(0))
     b=Cstr(ndoc.detached(0))
0
 
LVL 46

Expert Comment

by:Sjef Bosman
ID: 10766899
So you don't trust administrative procedures? If you're in a 300+ office company, administration should be paramount. So they can't guarantee the quality of the NAB? It's time for a managerial discussion, I think ;)
0
 

Author Comment

by:jforget1
ID: 10766904
sjef that did it adding the zero took care of the problem.
0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

I thought it will be a good idea to make a post as it will help in case someone else faces these issues. I trust this gives an idea how each entry in Notes.ini can mean a lot for the Domino Server to be functioning properly. This article discusses t…
  In today’s Arena we can’t imagine our lives without Internet as we are highly used to of it. If we consider our life style just for only 2 min we found that face to face communication is swapped by e-communication.  Every Where from Works place to…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now