Concept ขั้นตอนการทำ Run No แบบมี Profile เก็บเลขที่ล่าสุด แก้ปัญหา Error 32k
1. ทำการสร้าง view ตามรูป

2. ทำการสร้างฟอร์มในการเก็บ Profile ของเลขที่ล่าสุด

3. ในฟอร์มเอกสารที่ใช้งานให้มีฟิลด์ตามด้านล่างนี้ Key ที่ใช้จะต้องตรงกันกับใน View ตามรูปที่ 1

4. สคริปที่ใช้ในการทำเลขที่เอกสารอัตโนมัติ (Run No) ให้ระบุใน Query Save Event บนฟอร์มเอกสารตามรูป
Sub Querysave(Source As Notesuidocument, Continue As Variant)
On Error Goto Errhandle
Dim workspace As New NotesUIWorkspace
Dim session As New NotesSession
Dim db As NotesDatabase
Dim view As NotesView
Dim uidoc As NotesUIDocument
Set db = session.CurrentDatabase
Set uidoc = workspace.CurrentDocument
Set note = uidoc.Document
Dim LastNo As Long
Dim CurrentNo As Long
If note.DocNo(0) <> "" Then
Exit Sub
End If
Set view = db.GetView("$RunNo")
Call view.Refresh
' dummy = Evaluate(|@if@IsError(@DbLookup("":"nocache"; "":""; "$RunNo"; FormName; 2)|, note)
key = note.FormName(0)
Set doc = view.GetDocumentByKey(key, True)
If Not doc Is Nothing Then
LastNo = doc.RunNo(0)
CurrentNo = LastNo + 1
note.DocNo = doc.ApplicationCode(0) & "-" & note.DepartmentCode(0) & "-" & CurrentNo
doc.RunNo = CurrentNo
Call doc.Save(True, False)
Print "Document was generate runno " & Cstr(CurrentNo) & " successful."
End If
Exit Sub
Errhandle:
Print "Error in Querysave : " & " Err " & Err & " Line " & Cstr(Erl) & " = > " & Error
End Sub
หมายเหตุ
ในกรณีที่ต้องการทำเป็น XPages สามารถประยุกต์ใช้ได้โดยการแปลงส่วนของการ save ไปเป็น JavaScript เวอร์ชั้่นได้ครับ