LoginSignup
0
0

[ServiceNow] FormのAnnotationの表示・非表示を動的に制御する

Last updated at Posted at 2023-07-21

はじめに

ServiceNowのOOTBでは、FormのAnnotation(注釈)の表示・非表示を動的に制御することはできませんが、Annotationの記述方法と、Client Scriptの工夫によって、それを可能にします。
ここでは、IncidentのImpactフィールドを例に、選択された値によって、Annotationを表示したり、非表示にしたりする例を取り上げます。

Annotationの設定

IncidentのForm Layoutで、Impactフィールドの上のAnnotationを追加し、次のようにAnnotationを定義します。

Incident_FormLayout.png

Annotation Textの定義は次のように記述します。ここでのポイントは、HTML形式のTextでメッセージをSpanダグで囲み、id属性として適当な値を設定します。

Annotation Text
<span id="impact_annotation">
${gs.getMessage("When selecting High, check the impacted CI's business criticality.")}
</span>

Client Scriptの設定

次にIncidentのClient Scriptを次のように作成します。

Incident_ClientScript.png

Script
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
    //if (isLoading || newValue === '') {
    //   return;
    //}

    //Type appropriate comment here, and begin script below
    var $j = jQuery.noConflict();
    //If Impact is High
    if (newValue == '1') {
        // Show the annotation
        $j("#impact_annotation").parents("tr").show();
    } else {
        // Hide the annotation
        $j("#impact_annotation").parents("tr").hide();
    }
}

実行結果

ImpactフィールドでHighを選択した場合は、次のように表示されます。

Incident_ImpactHigh.png

High以外を選択した場合は、次のように表示され、Annotationが非表示になります。

Incident_ImpactNotHigh.png

0
0
0

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