バックグラウンド スクリプトで正規表現 (Regex) を使用してパターンに一致するレコードを検索する方法Summary<!-- /*NS Branding Styles*/ --> .ns-kb-css-body-editor-container { p { font-size: 12pt; font-family: Lato; color: #000000; } span { font-size: 12pt; font-family: Lato; color: #000000; } h2 { font-size: 24pt; font-family: Lato; color: black; } h3 { font-size: 18pt; font-family: Lato; color: black; } h4 { font-size: 14pt; font-family: Lato; color: black; } a { font-size: 12pt; font-family: Lato; color: #00718F; } a:hover { font-size: 12pt; color: #024F69; } a:target { font-size: 12pt; color: #032D42; } a:visited { font-size: 12pt; color: #00718f; } ul { font-size: 12pt; font-family: Lato; } li { font-size: 12pt; font-family: Lato; } img { display: ; max-width: ; width: ; height: ; } } バックグラウンドスクリプトで正規表現(Regex)を使用してレコードをクエリし、パターンに基づいて結果をフィルタリングします。この記事では、UUID形式などの特定の正規表現パターンに一致するフィールド値を持つレコードを識別するサンプルスクリプトを紹介します。 Release<!-- /*NS Branding Styles*/ --> .ns-kb-css-body-editor-container { p { font-size: 12pt; font-family: Lato; color: #000000; } span { font-size: 12pt; font-family: Lato; color: #000000; } h2 { font-size: 24pt; font-family: Lato; color: black; } h3 { font-size: 18pt; font-family: Lato; color: black; } h4 { font-size: 14pt; font-family: Lato; color: black; } a { font-size: 12pt; font-family: Lato; color: #00718F; } a:hover { font-size: 12pt; color: #024F69; } a:target { font-size: 12pt; color: #032D42; } a:visited { font-size: 12pt; color: #00718f; } ul { font-size: 12pt; font-family: Lato; } li { font-size: 12pt; font-family: Lato; } img { display: ; max-width: ; width: ; height: ; } } サポートされている全てのリリース Instructions<!-- /*NS Branding Styles*/ --> .ns-kb-css-body-editor-container { p { font-size: 12pt; font-family: Lato; color: #000000; } span { font-size: 12pt; font-family: Lato; color: #000000; } h2 { font-size: 24pt; font-family: Lato; color: black; } h3 { font-size: 18pt; font-family: Lato; color: black; } h4 { font-size: 14pt; font-family: Lato; color: black; } a { font-size: 12pt; font-family: Lato; color: #00718F; } a:hover { font-size: 12pt; color: #024F69; } a:target { font-size: 12pt; color: #032D42; } a:visited { font-size: 12pt; color: #00718f; } ul { font-size: 12pt; font-family: Lato; } li { font-size: 12pt; font-family: Lato; } img { display: ; max-width: ; width: ; height: ; } } シナリオ例 sys_created_by フィールドが UUID パターン(例:0127761e-41b4-4885-ba77-fc246e3300e2)と一致するトランザクションログエントリを検索します。 サンプルスクリプト システム定義 > スクリプト - バックグラウンドで次のスクリプトを実行します。 var gr = new GlideRecord("syslog_transaction");gr.addEncodedQuery("sys_created_onONThis week@javascript:gs.beginningOfThisWeek()@javascript:gs.endOfThisWeek()^urlSTARTSWITH/api/now/");gr.query();gs.info(gr.getRowCount());while (gr.next()) {var str = gr.sys_created_by;var regex = /([0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12})/;if(regex.test(str))gs.print('satisfied -- sys_id : ' + gr.sys_id + ' : sys_created_by : ' + gr.sys_created_by );else{gs.print('not satisfied -- sys_id : ' + gr.sys_id + ' : sys_created_by : ' + gr.sys_created_by );}} スクリプトのカスタマイズ ユースケースに合わせて以下の要素を変更します。 テーブル名: syslog_transaction をクエリ対象のテーブルに変更します。エンコードされたクエリ: addEncodedQuery フィルターを条件に合わせて調整します。テストするフィールド: gr.sys_created_by を評価対象のフィールドに変更します。正規表現パターン: UUID パターンを独自の正規表現に置き換えます。 出力例 [0:00:00.646] Script completed in scope global: script*** Script: 2638 *** Script: not satisfied -- sys_id : 9198c6241bab6d1038b80b05464bcb4d : sys_created_by : abc*** Script: not satisfied -- sys_id : 93098a641bab6d1038b80b05464bcbc9 : sys_created_by : xyz*** Script: satisfied -- sys_id : 935056e81bab6d1038b80b05464bcb33 : sys_created_by : 0127761e-41b4-4885-ba77-fc246e3300e2*** Script: satisfied -- sys_id : 93ddcee41bab6d1038b80b05464bcbf1 : sys_created_by : 0127761e-41b4-4885-ba77-fc246e3300e2 Related Links<!-- /*NS Branding Styles*/ --> .ns-kb-css-body-editor-container { p { font-size: 12pt; font-family: Lato; color: #000000; } span { font-size: 12pt; font-family: Lato; color: #000000; } h2 { font-size: 24pt; font-family: Lato; color: black; } h3 { font-size: 18pt; font-family: Lato; color: black; } h4 { font-size: 14pt; font-family: Lato; color: black; } a { font-size: 12pt; font-family: Lato; color: #00718F; } a:hover { font-size: 12pt; color: #024F69; } a:target { font-size: 12pt; color: #032D42; } a:visited { font-size: 12pt; color: #00718f; } ul { font-size: 12pt; font-family: Lato; } li { font-size: 12pt; font-family: Lato; } img { display: ; max-width: ; width: ; height: ; } } 参照製品ドキュメント: https://docs.servicenow.com/bundle/utah-api-reference/page/script/general-scripting/concept/c_RegularExpressionsInScripts.html