---
sourceDocument: オーストラリア API リファレンス
sourceDocumentLink: https://servicenow-prod.fluidtopics.net/r/ja-JP/api-reference

 Release :

    - australia

ft:locale :

    - ja-JP

ft:publication_title :

    - オーストラリア API リファレンス

ft:clusterId :

    - crapiref

bundleId :

    - crapiref

workflow :

    - Creator


---

# サーバーサイドスクリプトのユースケース

# サーバーサイドスクリプトのユースケース {#ariaid-title1}

* リリースバージョン: Australia
* 
* 更新日 2026年03月12日
* 
* ![](https://www.servicenow.com/docs/portal-asset/ico-clock) 所要時間：31分

サーバーサイドスクリプトのユースケースには、出力のログ記録、ユーザーオブジェクトの取得、日付/時刻値の変更などがあります。

## ビジネスルールからワークフロースクラッチパッドへのアクセス {#ariaid-title2}

カタログアイテムが要求されました。添付されたワークフローには、スクラッチパッドに値を入力するスクリプト実行アクティビティが含まれています。要求アイテムで実行されているビジネスルールから、スクラッチパッドの値を取得または設定します。

### 必須条件

必要なロール：admin。

名前：ビジネスルールからのワークフロースクラッチパッドへのアクセス。

タイプ：ビジネスルール。

テーブル：sc_req_item (要求アイテム)。

説明：カタログアイテムが要求されました。添付されたワークフローには、スクラッチパッドに値を入力するスクリプト実行アクティビティが含まれています。要求アイテムで実行されているビジネスルールから、スクラッチパッドの値を取得または設定します。

パラメーター：適用外。  
スクリプト：

    //the run script activity sets a value in the scratchpad
    workflow.scratchpad.important_msg = "scratch me";
     
    //get the workflow script include helper 
    var workflow = new Workflow();
     
    //get the requested items workflow context 
    //this will get all contexts so you will need to get the proper one if you have multiple workflows for a record 
    var context = workflow.getContexts(current); 
    //make sure we have a valid context 
    if (context.next()) { 
      //get a value from the scratchpad 
      var msg = context.scratchpad.important_msg; 
      //msg now equals "scratch me", that was set in the run script activity
     
      //add or modify a scratchpad value
      context.scratchpad.status = "completed"; 
      //we need to save the context record to save the scratchpad
      context.update(); 
    }

## 配送計画タスクに基づいたカタログアイテムのグループへのアサイン {#ariaid-title3}

デスクトップグループにアサインされたカタログタスクを持つ配送計画を使用する場合に、サービスカタログアイテムをデータベースグループにアサインします。

**必須条件**

必要なロール：admin  
警告:  
ここに記載されているカスタマイズは、特定のインスタンスで使用するために開発されたものであり、Now Support ではサポートされていません。この方法は現状のまま提供され、実装の前に完全にテストする必要があります。このカスタマイズに関するすべての質問およびコメントは、コミュニティ[フォーラム](http://community.service-now.com/)に投稿してください。

名前：配送計画タスクに基づいたカタログアイテムのグループへのアサイン。

タイプ：アサインルール。

説明：このアサインルールは、デスクトップグループにアサインされたカタログタスクを持つ配送計画を使用する場合に、サービスカタログアイテムをデータベースグループにアサインします。

**スクリプト：**  

    //Return catalog items that have no group but do have a delivery plan assigned var ri  = new GlideRecord ( "sc_cat_item" ) ;
    ri.addQuery("group", "=", null);
    ri.addQuery("delivery_plan", "!=", null);
    ri.query(); 
    while(ri.next()) {
        gs.log("Found an item"); 
        //Return tasks that point to the same delivery plan as the above item 
        var dptask = new GlideRecord("sc_cat_item_delivery_task");
        dptask.addQuery("delivery_plan", "=", ri. delivery_plan);
        dptask.query(); 
        while(dptask.next()) {
            gs.log("Found a task");
            var gp = dptask.group.getDisplayValue();
            gs.log(gp); 
            //If the task is assigned to desktop, assign the item's group to desktop
            if (dptask.group.getDisplayValue() == "Desktop") {
                ri.group.setDisplayValue("Desktop");
                gs.log("updating " + ri.getDisplayValue());
                ri.update(); 
                break; } } }

## 期間の計算 {#ariaid-title4}

タスクまたはプロセスの期限を指定する方法のユーザーへの提供が必要になることがよくあります。DurationCalculator スクリプトインクルードを使用すると、単純な期間または相対期間を使用して期日を計算できます。  
通常、期日を設定するには、合計時間ではなく作業時間を計算する必要があります。期日を決定する際に考慮するのは、1 日のうちの作業が行われる部分のみです。たとえば、ある作業が 10 時間かかるものの、平日のスケジュールで制限されている場合などです。作業が月曜日の 10 am に開始される場合、以下で計算するように、火曜日の 12 pm が期限になります。

    10am-5pm on Monday (6 hours) + 8am-12pm on Tuesday (4 hours)

DurationCalculator メソッドへの入力として使用できるスケジュールについては、「[スケジュールの作成と使用](https://www.servicenow.com/docs/access?context=c_UseSchedules&version=australia&pubname=australia-platform-administration&ft:locale=en-US)」を参照してください。

このスクリプトは、DurationCalculator を使用して期日を計算する方法を示しています。  

    /**
    * Demonstrate the use of DurationCalculator to compute a due date.
    *
    * You must have a start date and a duration. Then you can compute a
    * due date using the constraints of a schedule.
    */
     
    gs.include('DurationCalculator');
    executeSample();
     
    /**
    * Function to house the sample script.
    */function executeSample(){
     
        // First we need a DurationCalculator object.var dc =new DurationCalculator();
     
        // --------------- No schedule examples ------------------
     
        // Simple computation of a due date without using a schedule. Seconds// are added to the start date continuously to get to a due date.
        dc.setStartDateTime("5/1/2012");if(!dc.calcDuration(2*24*3600)){// 2 days
        	gs.log("*** Error calculating duration");return;}
        gs.log("calcDuration no schedule: "+ dc.getEndDateTime());// "2012-05-03 00:00:00" two days later
     
        // Start in the middle of the night (2:00 am) and compute a due date 1 hour in the future// Without a schedule this yields 3:00 am.
        dc.setStartDateTime("5/3/2012 02:00:00");if(!dc.calcDuration(3600)){
            gs.log("*** Error calculating duration");return;}
        gs.log("Middle of night + 1 hour (no schedule): "+ dc.getEndDateTime());// No scheduled start date, just add 1 hour
     
     
        // -------------- Add a schedule to the date calculator ---------------------
        addSchedule(dc);
     
        // Start in the middle of the night and compute a due date 1 hour in the future.// Since we start at 2:00 am the computation adds the 1 hour from the start// of the day, 8:00am to get to 9:00am
        dc.setStartDateTime("5/3/2012 02:00:00");if(!dc.calcDuration(3600)){//
            gs.log("*** Error calculating duration");return;}
        gs.log("Middle of night + 1 hour (with 8-5 schedule): "+ dc.getEndDateTime());// 9:00 am
     
        // Start in the afternoon and add hours beyond quiting time. Our schedule says the work day// ends at 5:00pm, if the duration extends beyond that, we roll over to the next work day.// In this example we are adding 4 hours to 3:00pm which gives us 10:00 am the next day.
        dc.setStartDateTime("5/3/2012 15:00:00");if(!dc.calcDuration(4*3600)){//
            gs.log("*** Error calculating duration");return;}
        gs.log("Afternoon + 4 hour (with 8-5 schedule): "+ dc.getEndDateTime());// 10:00 am.
     
        // This is a demo of adding 2 hours repeatedly and examine the result. This// is a good way to visualize the result of a due date calculation.
        dc.setStartDateTime("5/3/2012 15:00:00");// for(var i=2; i<24; i+=1){if(!dc.calcDuration(i*3600)){//
                gs.log("*** Error calculating duration");return;}
            gs.log("add "+ i +" hours gives due date: "+ dc.getEndDateTime());}
     
        // Setting the timezone causes the schedule to be interpreted in the specified timezone.// Run the same code as above with different timezone. Note that the 8 to 5 workday is// offset by the two hours as specified in our timezone.
        dc.setTimeZone("GMT-2");
        dc.setStartDateTime("5/3/2012 15:00:00");for(var i=2; i<24; i+=1){if(!dc.calcDuration(i*3600)){//
                gs.log("*** Error calculating duration");return;}
            gs.log("add "+ i +" hours gives due date (GMT-2): "+ dc.getEndDateTime());}}
     
    /**
    * Add a specific schedule to the DurationCalculator object.
    *
    * @param durationCalculator An instance of DurationCalculator
    */function addSchedule(durationCalculator){// Load the "8-5 weekdays excluding holidays" schedule into our duration calculator.var scheduleName ="8-5 weekdays excluding holidays";var grSched =new GlideRecord('cmn_schedule');
        grSched.addQuery('name', scheduleName);
        grSched.query();if(!grSched.next()){
            gs.log('*** Could not find schedule "'+ scheduleName +'"');return;}
        durationCalculator.setSchedule(grSched.getUniqueValue(),"GMT");}

### 単純な期間と相対期間 {#ariaid-title5}

タスクを完了するために必要な作業量を「相対期間」で表すことができます。

相対期間では、開始時間との相対関係で予想できる期限となる日時が決定されます。相対期間の例としては、「翌営業日の 4 pm まで」や「2 営業日後の 10:30 am まで」などがあります。  
相対期間を計算するには、「翌営業日」が何を意味するかを判断するために、カレンダーとタイムゾーンを考慮する必要があります。これは、有効な営業日とはいつであるかを定義しているのがカレンダーであり、タイムゾーンも結果に影響するためです。例として、「翌営業日の 4 pm まで」を考えてみます。

* 開始が月曜日の 12 pm の場合：翌営業日の 4 pm =\> 火曜日の 4 pm
* 開始が金曜日の 2 pm の場合：翌営業日の 4 pm =\> 次の月曜日の 4 pm
{#c_SImpleDurationVsRelativeDuration__ul_jr2_s5t_1q}  
注:  
多くの場合、「翌営業日」は開始日時によって定義されます。たとえば、「2 pm より前であれば翌営業日の 4 pm」は、現在の時刻が営業日の 2 pm を過ぎていると、実際にはその日から 2 営業日後が期日になることを意味します。

相対期間の詳細については、「 [Define a relative duration](https://www.servicenow.com/docs/access?context=t_DefineARelativeDuration&version=australia&pubname=australia-platform-administration&ft:locale=en-US)」を参照してください。

#### 単純な期間の計算 {#ariaid-title6}

このビジネスルールとスクリプトの例は、単純な期間を計算する方法を示しています。  

    var dur =new DurationCalculator();
    dur.setSchedule(current.schedule);
    dur.setStartDateTime("");
     
    if(current.duration_type==""){
             dur.calcDuration(current.duration.getGlideObject().getNumericValue()/1000);}else{
             dur.calcRelativeDuration(current.duration_type);}
     
        current.end_date_time= dur.getEndDateTime();
        current.work_seconds= dur.getSeconds();

このスクリプトは、DurationCalculator を使用して単純な期間を計算する方法を示しています。  

    /**
     * Sample script demonstrating use of DurationCalculator to compute simple durations
     * 
     */
     
    gs.include('DurationCalculator');
    executeSample();
     
    /**
     * Function to house the sample script.
     */
    function executeSample(){
     
        // First we need a DurationCalculator object.
        var dc =new DurationCalculator();
     
        // Compute a simple duration without any schedule. The arguments
        // can also be of type GlideDateTime, such as fields from a GlideRecord.
        var dur = dc.calcScheduleDuration("5/1/2012","5/2/2012");
        gs.log("calcScheduleDuration no schedule: "+ dur);
        // 86400 seconds (24 hours)
     
        // The above sample is useful in limited cases. We almost always want to 
        // use some schedule in a duration computation, let's load a schedule.
        addSchedule(dc);
     
        // Compute a duration using the schedule. The schedule
        // specifies a nine hour work day. The output of this is 32400 seconds, or
        // a nine hour span.
        dur = dc.calcScheduleDuration("5/23/2012 12:00","5/24/2012 12:00");
        gs.log("calcScheduleDuration with schedule: "+ dur);
        // 32400 seconds (9 hours)
     
        // Compute a duration that spans a weekend and holiday. Even though this
        // spans three days, it only spans 9 work hours based on the schedule.
        dur = dc.calcScheduleDuration("5/25/2012 12:00","5/29/2012 12:00");
        gs.log("calcScheduleDuration with schedule spaning holiday: "+ dur);
        // 32400 seconds (9 hours)
     
        // Use the current date time in a calculation. The output of this is
        // dependent on when you run it.
        var now =new Date();
        dur = dc.calcScheduleDuration("5/15/2012",new GlideDateTime());
        gs.log("calcScheduleDuration with schedule to now: "+ dur);
        // Different on every run.}
     
    /** 
     * Add a specific schedule to the DurationCalculator object.
     *  
     * @param durationCalculator An instance of DurationCalculator
     */
    function addSchedule(durationCalculator){
       //  Load the "8-5 weekdays excluding holidays" schedule into our duration calculator.
       var scheduleName ="8-5 weekdays excluding holidays";
       var grSched =new GlideRecord('cmn_schedule');
       grSched.addQuery('name', scheduleName);
       grSched.query();if(!grSched.next()){
            gs.log('*** Could not find schedule "'+ scheduleName +'"');
            return;}
        durationCalculator.setSchedule(grSched.getUniqueValue());}

#### 相対期間の計算 {#ariaid-title7}

相対期間計算スクリプトの例。  
このスクリプトは、「10 am を過ぎていれば翌日 4 pm」の相対期間を計算します。

    // Next day at 4pm if before 10am
    var days =1;
    if(calculator.isAfter(calculator.startDateTime,"10:00:00")) 
          days++;
     
    calculator.calcRelativeDueDate(calculator.startDateTime, days,"16:00:00");

このスクリプトは、DurationCalculator を使用して相対期間を計算する方法を示しています。  

    /**
     * Sample use of relative duration calculation.
     * 
     */
     
    gs.include('DurationCalculator');
    executeSample();
     
    /**
     * Function to house the sample script.
     */
    function executeSample(){
     
        // First we need a DurationCalculator object. We will also use
        // the out-of-box relative duration "2 bus days by 4pm"
        var dc =new DurationCalculator();
        var relDur ="3bf802c20a0a0b52008e2859cd8abcf2";
        // 2 bus days by 4pm if before 10am
        addSchedule(dc);
     
        // Since our start date is before 10:00am our result is two days from
        // now at 4:00pm.
        dc.setStartDateTime("5/1/2012 09:00:00");
        if(!dc.calcRelativeDuration(relDur)){
            gs.log("*** calcRelativeDuration failed");
            return;}
        gs.log("Two days later 4:00pm: "+ dc.getEndDateTime());
     
        // Since our start date is after 10:00am our result is three days from
        // now at 4:00pm.
        dc.setStartDateTime("5/1/2012 11:00:00");
        if(!dc.calcRelativeDuration(relDur)){
            gs.log("*** calcRelativeDuration failed");
            return;}
        gs.log("Three days later 4:00pm: "+ dc.getEndDateTime());}
     
    /** 
     * Add a specific schedule to the DurationCalculator object.
     *  
     * @param durationCalculator An instance of DurationCalculator
     */
    function addSchedule(durationCalculator){
      //  Load the "8-5 weekdays excluding holidays" schedule into our duration calculator.
      var scheduleName ="8-5 weekdays excluding holidays";
      var grSched =new GlideRecord('cmn_schedule');
      grSched.addQuery('name', scheduleName);
      grSched.query();
      if(!grSched.next()){
            gs.log('*** Could not find schedule "'+ scheduleName +'"');
            return;}
      durationCalculator.setSchedule(grSched.getUniqueValue(),"GMT");}

### 相対期間の実装方法 {#ariaid-title8}

cmn_relative_duration テーブルと DurationCalculator スクリプトインクルードを作成することで、相対期間を実装できます。

#### 始める前に

必要なロール：admin

#### 手順

1. cmn_relative_duration テーブルを作成します。
2. DurationCalculator スクリプトインクルードを作成します。
3. サンプルの相対期間エントリを作成します (たとえば、「4 pm までであれば翌営業日」)。
4. 相対期間をサポートするために必要なフィールドを SLA テーブルに追加します。
5. SLA の期間計算を変更します。
6. SLA の SLA パーセンテージタイマー計算を変更します (これは work_seconds を使用する必要があります)。
7. ワークフローにスケジュールフィールドを追加します： スケジュールとタイムゾーン (ワークフローテーブルのフィールドに基づいて選択)。
8. 期間サポートフィールドをワークフロータスクアクティビティに追加します。
9. タスクアクティビティの期間計算スクリプトを実装します。

#### 相対期間テーブルと DurationCalculator メソッド {#ariaid-title9}

cmn_relative_duration テーブルは、期間または相対期間のどちらかでの期日の定義をサポートしています。

このテーブルは、\[名前\] と \[スクリプト\] の 2 つのフィールドで構成されています。\[スクリプト\] フィールドには、相対期間計算スクリプトが含まれています。このスクリプトには、期日の計算に使用される「calculator」変数が含まれています。

DurationCalculator スクリプトインクルードを使用して、期間の計算を実行できます。このスクリプトインクルードで使用できるメソッドは次のとおりです。  
{#c_RelDurTblCalc__table_vbs_swt_1q__entry__2}

| メソッド | 説明 |
|-|-|
| setSchedule(String schedID, \[String timezone\]) | 期日の計算に使用するスケジュールとタイムゾーンを設定します。 |
| setStartDateTime(GlideDateTime start) | 期間計算のための開始時刻を設定します。\[開始\] が空の場合、現在の日付/時刻が使用されます。 |
| calcDuration(int seconds) | 終了日時を計算します。完了すると、this.endDateTime および this.seconds プロパティは、計算の結果を示すように設定されます。 |
| calcRelativeDuration(String relativeDurationID) | 指定された相対期間スクリプトを使用して期間を計算します。完了すると、this.endDateTime および this.seconds プロパティは、計算の結果を示すように設定されます。 |
| getEndDateTime() | 期間の終了日時を示す、calcDuration/calcRelativeDuration によって設定された this.endDateTime プロパティを取得します。 |
| getSeconds() | 期間中に実行される作業の合計秒数を示す、calcDuration/calcRelativeDuration によって設定された this.seconds プロパティを取得します。 注: これは、開始時間と終了時間の合計時間ではなく、合計作業時間であり、作業時間のパーセンテージを決定するために使用されます。 |
| getTotalSeconds() | 期間の開始時刻から終了時刻までの合計秒数を示す、calcDuration/calcRelativeDuration によって設定された this.totalSeconds プロパティを取得します。 |
[表 : 1. DurationCalculator スクリプトインクルードテーブル]

{#c_RelDurTblCalc__table_vbs_swt_1q}

相対期間スクリプトでは、次の関数が使用されます。  
{#c_RelDurTblCalc__table_ahm_gd5_1q__entry__2}

| 関数 | 説明 |
|-|-|
| boolean isAfter(GlideDateTime dt, String time) | 「time」は「dt」で指定された時刻より後になっているかどうか。dt が空白の場合、現在の日付/時刻が使用されます。時間は 24 時間形式の「hh:mm:ss」で表されます。 |
| calcRelativeDueDate(GlideDateTime start, int days, String endTime) | 「start」で始まり、スケジュールとタイムゾーンを使用して「days」を追加して、期日を計算します。作業の期日を特定できたら、その日の「endTime」に時間を設定します。完了すると、this.endDateTime および this.seconds プロパティは、計算の結果を示すように設定されます。「endTime」が空白の場合は、作業終了日の終了時間を使用します。 |
[表 : 2. 相対期間スクリプト関数]

{#c_RelDurTblCalc__table_ahm_gd5_1q}

## ユーザーオブジェクトを取得する {#ariaid-title10}

ビジネスルールやその他のサーバースクリプトでは、gs.getUser() メソッドがユーザーオブジェクトを返します。ユーザーオブジェクトは、現在ログインしているユーザーの内部表現であり、ユーザーやさまざまなユーティリティ機能に関する情報を提供します。

### このタスクについて

ユーザーオブジェクトで利用可能なスコープ対象メソッドのリストと説明については、「[GlideUser](https://servicenow-prod.fluidtopics.net/TgYHsFfz0WinXhBcG~7Ajg#GUserAPI "GlideUser API は、現在のユーザーと現在のユーザーロールに関する情報にアクセスするためのメソッドを提供します。")」を参照してください。

### 手順

1. 現在のユーザーを取得します。  

       var myUserObject = gs.getUser()

2. getUserByID メソッドを使用し、ターゲットレコードの `user_name` フィールドまたは `sys_id` を使用して別のユーザーをフェッチします。  
   例：  

       var ourUser = gs.getUser(); 
       gs.print(ourUser.getFirstName()); //print the first name of the user you are currently logged in as 
       newUser = ourUser.getUserByID(<user_sys_id>); //fetch a different user, using the sys_id of the target user record. 
       gs.print(newUser.getFirstName()); //first name of the user you fetched above 
       gs.print(newUser.isMemberOf('Capacity Mgmt'));

## ログ出力 {#ariaid-title11}

GSLog は、呼び出し元ごとに識別される sys_properties 値によって選択可能なログ出力のレベルを実装することで、スクリプトのログ記録とデバッグを簡素化するスクリプトインクルードです。

### ログレベル

ログは、debug、info、notice、warning、err、または crit のレベルを指定できます (BSD syslog.h 以降とフォロワー)。デフォルトのログ記録レベルは notice であるため、状況に応じてレベルを選択する必要があります。

### 使用する状況

イベントログ記録を実装するサーバー側スクリプトに使用します。

API リファレンスについては、「[GSLog()](https://servicenow-prod.fluidtopics.net/v5MbdqV5wrgzrrETfl1WdQ#GSLogBoth "GSLog は、呼び出し元ごとに識別される sys_properties 値によって選択可能なログ出力のレベルを実装することで、スクリプトのログ記録とデバッグを簡素化するスクリプトインクルードです。")」を参照してください。

詳細については、「[スクリプトのデバッグ](https://servicenow-prod.fluidtopics.net/MloaDTqMwyihvwopsW4jSA "セッションログと ServiceNow AI Platform デバッグツール (ウォークスルースクリプトデバッガーや UI に表示されるエラーメッセージなど) を使用して、スクリプトをデバッグします。")」を参照してください。

## GlideDateTime フィールド値の変更 {#ariaid-title12}

この例では、サーバーサイドスクリプトを使用して GlideDateTime フィールド値を変更する方法を示します。
次のサーバーサイドスクリプトの例は、GlideDateTime API を使用して値を変更する方法を示しています。同じ概念が GlideDate オブジェクトにも適用されます。  
注:  
次のスクリプトは、グローバルアプリケーションのみを対象としています。

    //You first need a GlideDateTime object
    //this can be from instantiating a new object "var gdt = new GlideDateTime()"
    //or getting the object from a GlideDateTime field
    //getting the field value (for example: var gdt = current.start_date) only returns the string value, not the object
    //to get the object use var gdt = current.start_date.getGlideObject(); (GlideElement)
    //now gdt is a GlideDateTime object
    var gdt = current.start_date.getGlideObject();
     
    //All methods can use negative values to subtract intervals
     
    //add 1 hour (60 mins * 60 secs)
    gdt.addSeconds(3600);
     
    //add 1 day
    gdt.addDaysLocalTime(1);
     
    //subtract 1 day
    gdt.addDaysLocalTime(-1);
     
    //add 3 weeks
    gdt.addWeeksLocalTime(3);
     
    //subtract 6 months
    gdt.addMonthsLocalTime(-6);
     
    //add 1 year, representing the date and time using the UTC timezone instead of the local user's timezone.
    gdt.addYearsUTC(1);
     
    //set the value of the GlideDateTime object to the current session timezone/format
    GlideSession.get().setTimeZoneName('US/Eastern');
    gdt.setDisplayValue('2018-2-28 00:00:00');
    gs.info('In ' + GlideSession.get().getTimeZoneName() + ": " + gdt.getDisplayValue());

関連項目：

* [GlideDateTime](https://servicenow-prod.fluidtopics.net/EykQEpagJJy6r4~z0xBdIg#c_GlideDateTime "GlideDateTime クラスは、GlideDateTime オブジェクトのインスタンス化や glide_date_time フィールドの操作など、GlideDateTime オブジェクトに対する操作を実行するためのメソッドを提供します。")
* [GlideDate - グローバル](https://servicenow-prod.fluidtopics.net/fthvoWNfsneUBZ5rD9ITtw#GlideDateAPI "GlideDate クラスは、GlideDate オブジェクトのインスタンス化や GlideDate フィールドの操作など、GlideDate オブジェクトに対する操作を実行するためのメソッドを提供します。")
* [GlideDate - スコープ対象](https://servicenow-prod.fluidtopics.net/mPPxsqT3rGPkEk5WTn97bw#c_GlideDateScopedAPI "スコープ対象の GlideDate クラスは、GlideDate オブジェクトのインスタンス化や GlideDate フィールドの操作など、GlideDate オブジェクトに対する操作を実行するためのメソッドを提供します。")
* [GlideDateTime - グローバル](https://servicenow-prod.fluidtopics.net/sX6jx~y7CQmLmvE~regDqg#c_GlideDateTimeAPI "GlideDateTime クラスは、GlideDateTime オブジェクトに対して操作を実行するためのメソッドを提供します。")
* [GlideDateTime - スコープ指定](https://servicenow-prod.fluidtopics.net/wTaFwoqoHkaw5dRdDfoOpA#c_GlideDateTimeScoped "スコープ対象の GlideDateTime クラスは、GlideDateTime オブジェクトに対して操作を実行するためのメソッドを提供します。")
* [GlideElement - グローバル](https://servicenow-prod.fluidtopics.net/fTiHnEvNeGD~RfuUaMUdAw#c_GlideElementAPI "GlideElement API には、フィールドとその値を扱うための便利なスクリプトメソッドが多数用意されています。GlideElement メソッドは、現在の Glide レコードのフィールドで使用できます。")
* [GlideElement - スコープ対象](https://servicenow-prod.fluidtopics.net/QV~Sg~onNeudOjbVEFHK0Q#c_GlideElementScopedAPI "スコープ対象の GlideElement API には、フィールドとその値を扱うための便利なスクリプトメソッドが多数用意されています。スコープ付き GlideElement メソッドは、現在の Glide レコードのフィールドで使用できます。")
* [GlideTime - スコープ指定](https://servicenow-prod.fluidtopics.net/ZQOa9oU7RG8PX9ALB1TJWg#c_GlideTimeScopedAPI "GlideTime API は、GlideTime オブジェクトのインスタンス化や GlideTime フィールドの操作など、GlideTime オブジェクトに対する操作を実行するためのメソッドを提供します。")
{#r_ModifyAGlideDateTimeFieldValue__ul_l51_1xl_cjc}

## カスタムキューを使用してイベントを処理する {#ariaid-title13}

大量のイベントや処理に時間がかかるイベントを作成するアプリケーションには、カスタムキューを使用できます。このタスクでは、カスタムキューとその監視プロセスを作成し、スクリプトを使用してキューにイベントを送信する方法を示します。

### 始める前に

必要なロール：admin  
注:  
この情報は、イベント処理を理解している上級ユーザーを対象としています。

### 手順

1. 移動先 システムポリシーイベントレジストリ.
2. カスタムキューを作成するイベントを選択します。  
   \[イベント登録\] フォームが表示されます。
3. イベント登録でイベントの \[キュー\] フィールドに入力します。  
   小文字のみを使用し、アンダースコア (_) 以外の特殊文字は使用しないでください。
4. \[送信\] をクリックします。  
   新しいイベントがイベント \[sysevent\] テーブルに一覧表示されます。

   次の例では、employeeOccasion イベントが生成されると my_queue に追加されます。イベントはキューに留まります。この問題を解決するには、イベントのキューを監視するプロセスを作成します。
5. 移動先 システムスケジューラスケジュール済みジョブスケジュール済みジョブ をクリックし、「 テキストインデックスイベントプロセス」という名前のスケジュール済みジョブを開きます。  
   \[
6. \[他のアクション\] メニューアイコン \[ ![他のアクション\] アイコン メニュー]())--\>をクリックし、\[ Insert and Stay \] を選択して、 テキストインデックスイベントプロセスのコピーを作成します。  
   重要:  
   かならずジョブをコピーし、\[テキストインデックスイベントの処理\] のスケジュール済みジョブを上書きしないようにしてください。
7. コピーしたスケジュールアイテムで、\[名前\] フィールドの値を変更します。
8. \[ジョブコンテキスト\] フィールドで、GlideEventManager() パラメーターの値を新しいキューの名前に置き換えます。  
   キュー監視プロセスは、サンプルの my_queue イベントキューでイベントを検索して処理します。

9. gs.eventQueue() メソッドの 5 番目のパラメーターを使用して、カスタムキューにイベントを送信します。  
   次のコードは、my_queue カスタムキューにイベントを送信する方法を示しています。

       gs.eventQueue('x_60157_employee_spe.employeeOccasion', todaysOccasions, todaysOccasions.number, todaysOccasions.u_employee.name, 'my_queue');

   注:  
   イベントが \[イベント登録\] にあり、キュー名が gs.eventQueue に指定されていない場合でも、\[イベント登録\] からのキューがイベントに割り当てられます。たとえば、`gs.eventQueue('x_60157_employee_spe.employeeOccasion')` は引き続きイベントを `my_queue` に関連付けます。`gs.eventQueue()` 呼び出しでキュー名が指定されている場合は、キューが優先されます。  
   \[イベント\] \[sysevent\] テーブルをチェックすることで、呼び出されたイベントが処理されたことを確認できます。
{#queues-create__steps_isy_nbk_tvb}

