はじめに
ServiceNowのOOTBでは、FormのAnnotation(注釈)の表示・非表示を動的に制御することはできませんが、Annotationの記述方法と、Client Scriptの工夫によって、それを可能にします。
ここでは、IncidentのImpactフィールドを例に、選択された値によって、Annotationを表示したり、非表示にしたりする例を取り上げます。
Annotationの設定
IncidentのForm Layoutで、Impactフィールドの上のAnnotationを追加し、次のようにAnnotationを定義します。
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を次のように作成します。
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を選択した場合は、次のように表示されます。
High以外を選択した場合は、次のように表示され、Annotationが非表示になります。