LoginSignup
4
0

【ServiceNow】リマインダー機能を作成してみた

Last updated at Posted at 2023-12-14

実現したいこと

ServiceNowで未承認のレコードがあった時にリマインダーを送りたい。

機能概要

  • sysapproval_approverテーブルで未承認のレコードをユーザ毎に取得
  • 未承認のレコードがあったらイベントを発火して通知を送信

用意するもの

  • Scheduled Jobs
  • Event Registry
  • Email Templates
  • Notification

作り方

1.Scheduled Jobsのスクリプト

Scheduled Jobs
var grUsr = new GlideRecord('sys_user')
grUsr.addQuery('active', true); 
grUsr.query();

while (grUsr.next()){

	var count = 0;
	var user = '';

	var gr = new GlideRecord('sysapproval_approver');
	gr.addQuery('approver', grUsr.sys_id);
	gr.addQuery('state', 'requested');
	gr.query();

	while (gr.next()){
		// Email Templateに引き渡す値を変数に格納
		count = count + 1;
		user = gr.approver.getDisplayValue();
	}

	if (count > 0 ){
		// 未承認のものが1件以上あったらメール送信するイベントを発火 
		gs.eventQueue('remainder', gr, count, user);
	}

}

2.Event Registrationの設定

Event Registration.png

3.Email Templateの設定

Email Template.png
\${event.parm1},${event.parm2}はイベント発火の際に引き渡された変数になります。

4.Notificationの設定

項目 設定値 メモ
Name u_remainder_mail 任意の値
Table sysapproval_approver 承認テーブルを指定
Category Approval
Active True
When to send - Send when Event is fired
When to send - Event name remainder 上記で作成したイベント名を選択
When to send - Who will receive User/Groups in fields Approver
What it will contain - Email template remainder 上記で作成したテンプレートを選択

動作確認

個人の開発インスタンスのEmailにメールが作成されていることを確認。
Email.png

簡単なソースですが、リマインダー機能を実装できました。

4
0
1

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
4
0