排他制御(文書保存時競合判定)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
〇Xpages部(データバインド箇所抜粋)
 
  <xp:this.data>
    <xp:dominoDocument var="document1" formName="FormTest"
      action="openDocument" computeWithForm="onsave"
      concurrencyMode="exception">
    </xp:dominoDocument>
  </xp:this.data>
   
   
---------------------------------------------
〇SSJS部(文書保存処理)
 
function testConflict(){
  try{
    //エラーメッセージ用
    viewScope.errorMsg = "";
     
    //保存時競合の場合は例外発生( currentDocumentのconcurrencyMode="exception")
    document1.save();
 
  }catch(e){
    // エラー内容で競合かどうか判別
    var message = @Implode(e.message);
    if(@Contains(message, "Document has been saved by another user - Save has been cancelled")){
      viewScope.errorMsg = "競合が発生しました。"
    }
    print("error:"+e)
 
  }
}





同じ文書を複数人で編集する事が多いケースで、競合文書を作成したくない場合に有効な処理です。

 

XPage部のデータバインド部分で
concurrencyModeプロパティの値を"exception"に設定する。
上記を設定することで、文書保存時(NotesXspDocument)に競合が発生する場合は例外が発生します。
その例外をtry,catchでcatchします。
エラー内容を確認して競合かどうかをチェックします。

 


JavaScript (Server)
kyone
July 17, 2018 at 4:52 PM
Rating
Overall rating is 5.00 by 1 person(s)
0





No comments yetLogin first to comment...