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

  • リリースバージョン: Zurich
  • 更新日 2025年07月31日
  • 所要時間: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();
        }
        }