AgeNt is To gEnEratE CuTomiZe RunnIng nUmbEr

Thursday, March 13, 2008

Usually we use @Unique to generate the document reference number.
Now, this agent used to generate customize running number for the document once the document has been submitted [Call agent from Submit Button of the form]. The running number can be set up from setup form (a).

In this example I used Year and Start Running Number from.

refNum = "PS" + "/"+Cstr(Cint(sldoc.runNumber(0)) + 1) + "/" + sldoc.runYear(0)

The output will be like PS/0001/2008. The running number will + 1 for the next document submitted.

sldoc.runNumber = Cstr(Cint(sldoc.runNumber(0)) + 1)


(a) Running Number Setup Form

(b) Running Number Setup View (1 column Year Sort: Ascending, Type: Standard) (2nd Column RunNumber Sort: None, Type: Standard))

Note: If the setup got Author&Reader access; you need to add composer as Author. Therefore I suggest, not need to introduce Author&Reader's field in setup


Agent Name: RunNumber | agntRunNum
Runtime: Action Menu Selection
Trigger: On Event
Target: All Selected Documents

Target Field : Pick Slip No.
Type: Text/Computed

Sub Initialize

On Error Goto handler

Dim session As NotesSession
Dim AppDb As NotesDatabase
Dim doc As NotesDocument
Dim dc As NotesDocumentCollection
Dim refNum As String

Dim slview, view14 As notesview
Dim sldoc, doc14 As NotesDocument

Set session = New NotesSession
Set AppDb = session.CurrentDatabase
Set currDoc = session.DocumentContext

'//currDoc - current doc
'//ref_code = PsNo
'//view - lsvRunNum

If currDoc.PsNo(0) = "" Or currDoc.PsNo(0) = "-" Then

'// Checking if the doc number not exist

Set slview = AppDb.GetView("lsvRunNum")
'========================
Set sldoc = slview.getdocumentbykey(Cstr(Year(Today())),True)

'// sldoc.runNumber(0) - runNumber
'// sldoc.runYear(0) - runYear

If Not sldoc Is Nothing Then

refNum = "PS" + "/"+Cstr(Cint(sldoc.runNumber(0)) + 1) + "/" + sldoc.runYear(0)
sldoc.runNumber = Cstr(Cint(sldoc.runNumber(0)) + 1)
currDoc.PsNo = refNum
Call sldoc.Save(True, True)
Call currDoc.Save(False, True)

End If
End If

Exit Sub

handler:
Msgbox "Error in PickSlipRunNumber sub. At line : " & Erl() & ". Error message is : " & Error()
Exit Sub

End Sub

0 comments: