---
sourceDocument: Xanadu Now Platform の管理
sourceDocumentLink: https://servicenow-prod.fluidtopics.net/r/ja-JP/xanadu/platform-administration

 Release :

    - xanadu

ft:locale :

    - ja-JP

ft:publication_title :

    - Xanadu Now Platform の管理

ft:clusterId :

    - platadm

bundleId :

    - platadm

workflow :

    - Platform


---

# フィールド値の存続期間スクリプトのサンプル

# フィールド値の存続期間スクリプトのサンプル {#ariaid-title1}

* リリースバージョン: Xanadu
* 
* 更新日 2024年08月01日
* 
* ![](https://www.servicenow.com/docs/portal-asset/ico-clock) 所要時間：1分

既存のオープン インシデントメトリクスの定義をレビューし、独自のカスタムメトリクスを作成する方法を確認してください。

このスクリプトは、インシデントが終了すると、期間の値を提供するか、期間の処理を停止します (回答変数を false に設定 ) 。  

    // script can set answer to false to terminate processing of the metric
        // mi - MetricInstance
        // answer
        if (!current.active) {
        answer = false;
        mi.endDuration();
        gs.log("Closing field durations");
        closeDurations(mi.current);
        }
        
        function closeDurations(current) {
        var now_GR = new GlideRecord('metric_instance');
        gr.addQuery('id', current.sys_id);
        gr.addQuery('calculation_complete', false);
        gr.addQuery('definition.type', 'field_value_duration');
        gr.query();
        while (gr.next()) {
        gs.log("closing: " + gr.definition.name + " for: " + current.number);
        var definition = new GlideRecord('metric_definition');
        definition.get(gr.definition);
        var mi = new MetricInstance(definition, current);
        mi.endDuration();
        }
        }


