LoginSignup
0
0

More than 5 years have passed since last update.

ビューから選択した文書のカテゴリを一括で変更する

Last updated at Posted at 2018-06-06

ビューから選択した文書のカテゴリを一括で変更する

概要

 ディスカッションなどのDBのカテゴリを一括で変更したいときに、ビューのボタンに埋め込んで使うスクリプト。特徴は以下の通り。

  • 1文書の場合、image.png印をつけずともカテゴリを変更可能
    • NotesUIViewクラスのCaretNoteIDプロパティを使うことで、現在ビューでハイライトされている文書のオブジェクトを取れる
  • 返答文書のカテゴリ変更は行わない
    • $Refフィールドの有無で判定

サンプルコード

Sub Click(Source As Button)
' 初期設定
    Dim ss As New NotesSession
    Dim ws As New NotesUIWorkspace
    Dim thisUIView As NotesUIView
    Dim selectedDocCol As NotesDocumentCollection
    Dim targetDoc As NotesDocument
    Dim category As String

    Set thisUIView = ws.CurrentView                 ' 現在ユーザーに見せているビューのオブジェクトを取得
    Set selectedDocCol = thisUIView.Documents               ' 現在選択されている文書の一覧を取得


' 変更したい値をインプット
    category = ws.Prompt(3, "カテゴリ入力", "変更後のカテゴリを入力してください")


' 選択した文書がない場合は、ビューで現在ハイライトされている (カレットの場所にある) 文書を変更(@式と同じ挙動をする)
    If selectedDocCol.Count = 0 Then
        Set targetDoc = ss.CurrentDatabase.GetDocumentByID(thisUIView.CaretNoteID)  ' ビューでハイライトされている (カレットの場所にある) 文書

        If targetDoc Is Nothing Then
            Exit Sub
        End If

        If targetDoc.HasItem("$Ref") Then   ' 返答文書であれば、カテゴリ変更を行わない
        Else
            Call targetDoc.ReplaceItemValue("Categories", category)
            ' 複数のフィールドの値を変えたければここにそのコードを追加
            Call targetDoc.Save(True, True)
        End If
    Else

' 選択した文書がある場合は、selectedDocColから一文書ずつ取り出して、順番にカテゴリ変更を実施
        Set targetDoc = selectedDocCol.GetFirstDocument
        Do While Not targetDoc Is Nothing
            If targetDoc.HasItem("$Ref") Then   ' 返答文書であれば、カテゴリ変更を行わない
            Else
                Call targetDoc.ReplaceItemValue("Categories", category)
                ' 複数のフィールドの値を変えたければここにそのコードを追加
                Call targetDoc.Save(True, True)
            End If

            Set targetDoc = selectedDocCol.GetNextDocument(targetDoc)
        Loop
    End If

    Call ws.ViewRefresh
End Sub
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0