I have a document that contains a field where the user will enter in a number and the number can only be used once. I have found a code to prevent the same number from being used, but now if you try to edit the form it will not save because the code is seeing that the number has been used already as if it were a new document being entered in and not an old one that is being edited. Any suggestions?
Subject: Editable Form
How are you checking against other documents?
You need to also add to your code that if the universalid of the document you are in matches the universalid of the document it has found whilst searching, then ignore it as it is the same document!
Subject: Editable Form
Couple of ideas:
(1) Add to the validation check @IsNewDoc and @IsDocBeingSaved
(2) If you have the documents ID stored in a field, when you do the check to see if that number has been used before, return the documentID and check to see if the DocID is the same as the current document, if so then don’t fail the validation.
Subject: RE: Editable Form
The code is in script though.
Subject: RE: Editable Form
Then use the second example.
When the code checks if the number has been used before, take the doucment that is returned and make sure that it’s docID is not the same as the current DocID. If it is the same then you’re dealing with the same document and you can let it save.
Subject: RE: Editable Form
Or just get a handle to the uidoc, and check the IsNewDoc property. If the doc is new and a doc already has the number assigned, don’t let it save. If the doc is not new, then let it save since it probably found itself.
If you’re doing the validation in QuerySave, just test Source.IsNewDoc.