イベントの作成
適切な既存のイベントがない場合は、独自のイベントを作成できます。
始める前に
このタスクについて
手順
- 移動先 すべて > システムポリシー > イベント > レジストリ.
- [新規] をクリックし、フォームに入力します。
- [ビジネスルール] 関連リンクをクリックします。
-
ベースシステムテーブルのイベントを作成する場合は、テーブルの既存のイベントビジネスルールを選択します。
たとえば、sc request events ビジネスルールを選択してカスタム要求イベントを作成します。
-
既存のイベントビジネスルールを更新する場合は、[スクリプト] に新しい条件を追加します。
次のサンプルスクリプトは、ユーザーのシステム ID が parm1 で、ユーザーのユーザー名が parm2 の request.commented イベントを追加します。
if (current.operation() != 'insert' && current.comments.changes()) { gs.eventQueue('request.commented', current, gs.getUserID(), gs.getUserName()); } -
カスタムテーブルのイベントを作成する場合は、データベース操作の後に実行される新しいビジネスルールを作成します。
たとえば、次のビジネスルールは、マーケティングイベントと呼ばれるカスタムアプリケーションに対していくつかのイベントを定義します。
表 : 1. イベントビジネスルールのサンプル フィールド 値 名前 出席者のイベント テーブル 出席者 [x_snc_marketing_ev_attendee] アプリケーション マーケティングイベント 詳細 選択済み 時期 トランザクションの後 挿入 選択済み 更新 選択済み 削除 選択済み スクリプト 次のようなカスタムスクリプトを追加します。- 現在のレコードで 1 つ以上の条件をチェックします。
- gs.eventQueue() メソッドを呼び出し、イベント名を指定します。
コードサンプルを参照してください。
注:[フィルター条件]、[ロールの条件]、または [条件] 値を追加する場合は、想定どおりにビジネスルールが実行されることを確認します。(function executeRule(current, previous /*null when async*/) { //This function will be automatically called when this rule is processed. //Add event when attendee inserted if(current.operation() == 'insert' && current.marketing_event.changes()) { gs.eventQueue('x_snc_marketing_ev.attendee.added', current, current.marketing_event, current.email); } //Add event when marketing event changes if(current.operation() == 'update' && current.marketing_event.changes()) { gs.eventQueue('x_snc_marketing_ev.attendee.deleted', previous, previous.marketing_event, previous.email); gs.eventQueue('x_snc_marketing_ev.attendee.added', current, current.marketing_event, current.email); } //Add event when attendee deleted if(current.operation() == 'delete') { gs.eventQueue('x_snc_marketing_ev.attendee.deleted', current, current.marketing_event, current.email); } })(current, previous); - イベントを登録します。