I am having trouble utilizing a profile document to hold and provide a new document number. Here’s my code:
Sub Querysave(Source As Notesuidocument, Continue As Variant)
Dim workspace As New NotesUIWorkspace
Dim uidoc As NotesUIDocument
Dim session As New NotesSession
Dim doc As NotesDocument
Dim db As NotesDatabase
Set db = session.CurrentDatabase
Set uidoc = workspace.CurrentDocument
Set doc=uidoc.Document
Dim errorlist As Variant
'Bunch of code here that validates the user’s input and creates / displays an errorlist, works great.
'Retrieve next sequential number if document is a new document
If uidoc.IsNewDoc = True Then
Dim CounterDoc As NotesDocument
Set CounterDoc = db.getprofiledocument("CounterDoc")
thisNumber = CounterDoc.GetItemValue("Counter")
Call uidoc.FieldSetText("IncidentNumber", Cstr(thisNumber(0)))
CounterDoc.Counter = thisNumber(0) + 1
Call CounterDoc.Save(False, False)
End If
“Counter” is an editable number field with a default value of 0 on the profile document “CounterDoc”.
“IncidentNumber” is a text field with a default value of “New” on the main document which has the above code in the Querysave event.
I wish to drop that retrieved number into a field “IncidentNumber” as text, because later ‘child’ documents will have document numbers like 12ACC and 12SCH.
I get a type mismatch at CounterDoc.Counter = thisNumber(0) + 1. Debugger says that thisNumber is a variant and thisNumber(0) is a string and = “”
I’m staying away from response type docs because I can’t control ACC and SCH getting .1 and .2 consistently, respectively. Just doesn’t feel clean.
Further - I have virtually identical code working perfectly (without the suffix stuff) in a different application. Only the form and field names are different.
I’m WAAAY stumped. I’m a new scripter, so use easy words! :o)
Subject: I tested your code and it works!
The error, I believe, is caused by not getting a handle on the thisnumber = value.
Subject: Might be the field on the profile doc can’t be found?
When I look at the debugger variables, I see the CountDoc there, but the single field Counter does not appear in the Items section under CountDoc. Only three items are there $Name, $NoPurge, and $ConflictAction. I don’t have any security set on CountDoc or the field Counter. Suggestion for me?
Subject: RE: Profile Doc problem
A few points.
The assigning of sequential numbers is discussed in the forum FAQ. Please consult this resource before posting.
Never use a profile document for assigning sequential document numbers. This only works when you have just one user of the application, because each workstation caches the profile document contents. Profile documents are not intended as a means of sharing up to the minute information between different users. Use a regular document instead, and either use document locking or a conflict-sensitive save (see doc of NotesDocument.Save method) to assure you’re not getting a duplicate.
Always use Option Declare. I don’t see a declaration of thisNumber.
The fact that you’re telling us the type and default value of the Counter field, makes me think you have a basic misunderstanding. The definition of the field on the form is totally irrelevant to how back-end code works. You can assign any field to any value you want, of whatever type. The form only comes into play when you edit the document on screen or call ComputeWithForm.
Try this script in a button:
Sub Click(Source As Button)
thisnumber = Split("", ",")
Print thisnumber(0) + 1
End Sub
This reproduces the situation you’re describing, and it gives me a Type Mismatch error too. Why? Because “” is not a number, so you can’t add 1 to it. You need a special case to handle this situation.
Make sure the
Subject: RE: Profile Doc problem
Thank you Andre. I’m new to the forum and hadn’t found the FAQs of FAQs yet. Your suggestion of using a regular document was helpful and effective.