Lotusscript expert needed

I have the following agent which works beautifully after the first sequential number has been assigned. Now that the database has been moved to production its not prompting if there is no previous sequential number.

Can anyone tell me why my code is failing? Thanks!

Sub Initialize

Dim s As New notesSession

Dim ws As New notesuiworkspace

Dim db As notesDatabase

Dim profileDoc As notesDocument

Dim uidoc As notesuiDocument

Dim thisDoc As NotesDocument

Dim seqNumber As Long

Dim seq As Long

Dim inputStr As String

Dim qtNumber As String

Dim un As String

Dim unInitials As String

'First, check to see if the Seq number document already exists.

Set db= s.currentDatabase

Set uidoc=ws.currentDocument

Set thisDoc=uiDoc.Document



Set profileDoc = db.Getprofiledocument("SeqNumberDoc")

If (Cstr(profileDoc.SeqNumber(0))="") Then

'if Not, prompt for the number

	inputStr=Inputbox ( "Please specify a number:" , "Enter Number" )

Else

'if so, prompt for a new number, with the existing number as a default

	inputStr = Cstr(profileDoc.SeqNumber(0))

End If

unInitials=thisDoc.Initials(0)

qtNumber=thisDoc.IssueNum(0)

seqNumber=Clng(profileDoc.SeqNumber(0))

thisDoc.IssueNum=unInitials & Cstr(seqNumber)

profileDoc.SeqNumber=seqNumber + 1

'Verify that the input was numberic

On Error Goto aa



seq =Clng(inputStr)

aa:

If seq=0 Then 

	mb=Msgbox("The value that you entered was not numeric or was zero. Please try again.",16,"Error")

	Exit Sub

End If



Set thisDoc = uidoc.document

unInitials = thisDoc.Initials(0)

qtNumber=thisDoc.IssueNum(0)

Call profiledoc.save(1,0)



If thisDoc.saveOptions(0) = "0" Then Exit Sub

If qtNumber<> "<<Draft>>" Then Exit Sub

Set profileDoc = db.Getprofiledocument("SeqNumberDoc") 

seqNumber= Clng(profileDoc.SeqNumber(0))

thisDoc.IssueNum= unInitials &Cstr(seqNumber) 

profileDoc.SeqNumber = seqNumber + 1

Call thisDoc.save(1,1)

'Notify the user that the number has been successfully changed.

'mb=Msgbox("The sequential application number has been set to " &inputStr,64,"Number Set")

End Sub

Subject: Lotusscript expert needed

I am bumbed Angie, you broke my rule/advice about keeping your dims and sets together (it makes it easier to find things if nothing else).

I do not see where you are saving the profile doc after making the change. ALso, you have Cing instead of Cint.

Subject: RE: Lotusscript expert needed

Sorry everyone, this was code which I inherited and was expected to modify rather than rewrite.

Anyway, I was instructed to use this code but I do see your point regarding profile docs. My question is profile doc and Profile doc, huh?

So when profile doc is used in script it caches it on the client? Not good, why would my predecessor have written code like that? So I’d be better with a Profile doc (actual form) with a field for lookup. This database will be located on a single server, accessed by very few employees and rarely accessed at that.

I don’t have it coded for int because its really the users initials + the number. What I see in debugger is that it calls the agent and the agent log says it ran. I never see the agent actually go thru debugger. I also never see profile doc in the debugger either.

Is there anyway this code can be made to work or should I scrap it completely? Thanks!

Subject: RE: Lotusscript expert needed

I think I already gave yo code that does this Angie. Take a look. If not here it is again:

you of course would have to tweak this abit. Hopefully by looking at the code you can see what you need to build.

Sub setDocumentNumber (db As NotesDatabase, doc As NotesDocument, docWFDefaults As NotesDocument, strSelectedAction As String)

Dim strRequestNumber As String

strRequestNumber=doc.Request_Number(0)

If strSelectedAction=

  docWFDefaults.admWFApprovalAction(0) And

  strRequestNumber="New" Then

Dim pad As String

Dim viewNumber As NotesView

Set viewNumber=db.GetView

 ("(NumberAssignment)")

Dim docNumber As NotesDocument

Set docNumber=viewNumber.GetFirstDocument

Dim numberAssigned As Variant

numberAssigned=docNumber.LastNumberCreated(0)

Dim newNumber As Variant

newNumber=numberAssigned+1

If newNumber <10 Then

pad = "000"

Elseif newNumber >=10 And newNumber <= 99 Then

pad = "00"

Elseif newNumber>=100 And newNumber<=999 Then

pad = "0"

Elseif newNumber>=1000 And newNumber<=9999

Then

pad = 0

End If

doc.Request_Number=

docWFDefaults.admWFTicketPrefix(0) & pad$ &

  newNumber

docNumber.LastNumberCreated=newNumber

Call docNumber.Save(True, False)

End If

End Sub

Subject: RE: Lotusscript expert needed

Thanks File Save,It may be that I’m just not reading your code correctly. If you do not already have an initial number on the profile doc. How do you prompt for it?

That seems to be what was failing with my code and I’m not sure how to modify your code to my needs. I had no initial number, it doesn’t prompt and my issueNum field is left as <>.

Thanks!

Subject: RE: Lotusscript expert needed

I set a number in the document when I create the document that is stored in that view.

Subject: Lotusscript expert needed

Have you followed along in the debugger and made sure that you’re getting the profile doc and that the profile doc has an appropriate value?

Subject: RE: Lotusscript expert needed

I really hate to do this, but I have to tell you that using a Profile Document for this purpose is a very bad idea. It will work just great in single-user testing, but if there are multiple users of the database, you’re almost guaranteed to wind up with duplicate numbers everywhere. The problem is that Profile Documents are cached by the client (that’s what makes them good for keeping settings that are unlikely to change often, but that need to be looked up quite often).

When a user opens the database and creates a new document, they will get the profile document the first time the code calls for it, along with the current sequence number at that time. No matter how many more users create documents in the database, as long as that user has the database open, the value in his/her in-memory version of the profile document will not change, except to reflect what that single user has done. Multiple users creating multiple documents will give multiple duplicate numbers. Guaranteed.

Subject: RE: Lotusscript expert needed

Exactly. When you (Angie) and I talked about this, I spoke of it in terms of a ‘profile’ document as Opposed to a “Profile” document, with the former being a dummy document stored in a view.