[LotusScript]文書の作成日で識別番号を発行する

文書に識別番号を付与する場合に作成日を利用することがある。
(xx-20140203-001など)

LotusScriptではFormat関数を利用して自動発番を以下のように実装する

  1. 文書を作成日でソートしたビュー(vwCount)を作成
    ※第1列のデータの種類は作成日を昇順or降順にソートし値の種類をDate/Timeに設定
    1. スクリプトライブラリで識別番号取得用の関数(getID)を作成

      Function getID() as String
        Dim session as new NotesSession
        Dim db as NotesDatabase
        Dim vw as NotesView
        Dim dc as NotesDocumentCollection

        set db = session.getCurrentDatabase()
        set vw = db.getView("vwCount")  '文書カウント用のビューを取得

        set dc = vw.getAllDocumentsByKey(Today, True) '作成日が今日の文書を取得

        getID = "xx-" _  '接頭文字
        & Format(Today, "yyyymmdd") _  '今日の日付
        & "-" & Format(dc.Count + 1, "000")  '作成日が今日の文書数+1を3桁に変換
      End Function
    2. フォームのQueryOpenイベントに以下のコードを追加
      ※上記で定義したスクリプトライブラリを取り込む

      Sub QuerySave(Source as NotesUIDocument, Continue as Variant)
        Const FLD_ID = "docID" '文書の識別番号フィールド名

        Dim doc as NotesDocument

        set doc = Source.Document

        call doc.replaceItemValue(FLD_ID, getID())  'バックグラウンドでフィールドを更新
        call doc.save(True, True) 'バックグラウンド文書を保存
      End Sub