notesrookie
asked on
Followup Question to Previous Post
Greetings all,
The post i question, https://www.experts-exchange.com/questions/21921926/Setting-ticket-number-using-latest-work-request.html, where I ask about sequential numbering.
I started thinking (how dangerous!) about marilyng's cautions about checking for duplicate numbers and how lucky I was that I wouldn't have to do so since the application is only on one server. But the more I thought about it, the more I thought that perhaps there just maybe the chance that 2 people may be composing a work request at almost the same millisecond and that my code would duplicate a work request number. Do you think it's a good idea to check that the work request number exists before being assigned to the work request. And, if so, would my additional code below work?
Set db = session.CurrentDatabase
Dim view As NotesView
Set view = db.GetView( "vAllNum" ) 'this view sorted by num, descending
Set doc= view.GetFirstDocument 'yep, it exists
Do Until Typename(doc.TicketNumber( 0)) <> "STRING" 'chk for blank ticket num
Set doc=view.GetNextDocument(d oc) 'if blank go get next doc
Loop 'break out of loop, valid ticket num
acount = doc.TicketNumber(0) + 1 'increment ticket number
'check that this ticket number does not exist (just in case another ticket was created at almost the same time
Dim chkdoc As NotesDocument
Set chkdoc = view.GetDocumentByKey(acou nt, True) 'try to get doc w/same ticket num
Do While Not (chkdoc Is Nothing) 'if doc exists
acount = doc.TicketNumber(0) + 1 'increment ticket number
Set chkdoc = view.GetDocumentByKey(acou nt, True) 'and check again
Loop 'break out of loop if doc does not exist
note.TicketNumber = acount
Thank you.
The post i question, https://www.experts-exchange.com/questions/21921926/Setting-ticket-number-using-latest-work-request.html, where I ask about sequential numbering.
I started thinking (how dangerous!) about marilyng's cautions about checking for duplicate numbers and how lucky I was that I wouldn't have to do so since the application is only on one server. But the more I thought about it, the more I thought that perhaps there just maybe the chance that 2 people may be composing a work request at almost the same millisecond and that my code would duplicate a work request number. Do you think it's a good idea to check that the work request number exists before being assigned to the work request. And, if so, would my additional code below work?
Set db = session.CurrentDatabase
Dim view As NotesView
Set view = db.GetView( "vAllNum" ) 'this view sorted by num, descending
Set doc= view.GetFirstDocument 'yep, it exists
Do Until Typename(doc.TicketNumber(
Set doc=view.GetNextDocument(d
Loop 'break out of loop, valid ticket num
acount = doc.TicketNumber(0) + 1 'increment ticket number
'check that this ticket number does not exist (just in case another ticket was created at almost the same time
Dim chkdoc As NotesDocument
Set chkdoc = view.GetDocumentByKey(acou
Do While Not (chkdoc Is Nothing) 'if doc exists
acount = doc.TicketNumber(0) + 1 'increment ticket number
Set chkdoc = view.GetDocumentByKey(acou
Loop 'break out of loop if doc does not exist
note.TicketNumber = acount
Thank you.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Whoops.. forgot to mention, notesrookie, congratulations!! YOU ARE the person who inherited a Q&D solution. Welcome to the club.:)
and most people pooh-pooh me about this topic.
and most people pooh-pooh me about this topic.
Pooh-pooh...
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Yes, I know I inherited a Q&D database. Isn't that always the case? marilyng, thanks for the FAQs os FAQs. Great as reference for a whole bunch of other things. And I don't know how long I'll be here
And, sjef, i like your idea about the lock and unlock non-referenced document. I could just do a check for whether that doc is unlocked before assigning the work request number.
Thanks for the great suggestions.
And, sjef, i like your idea about the lock and unlock non-referenced document. I could just do a check for whether that doc is unlocked before assigning the work request number.
Thanks for the great suggestions.
Marilyng,
I'm in the UK, and SOX does come into play.
Personally I don't give users the ability to delete documents, so in your scenario:
User A opens document- reserves 123 number
User B opens and saves 124
User C opens and saves 125
User A returns and cancels 123... This will still have been saved as a document with the person's name, reason for cancelling (if applicable) etc.
True it's not the perfect solution, but its a working one ;)
Depends on your application and environment of course.
I'm in the UK, and SOX does come into play.
Personally I don't give users the ability to delete documents, so in your scenario:
User A opens document- reserves 123 number
User B opens and saves 124
User C opens and saves 125
User A returns and cancels 123... This will still have been saved as a document with the person's name, reason for cancelling (if applicable) etc.
True it's not the perfect solution, but its a working one ;)
Depends on your application and environment of course.
that would be true, and a good example!
@If(@IsNewDoc;
@Command([FileSave]);
@Command([ViewRefreshField
This way as soon as a new document is created the next sequential number is taken.
Hope this helps!