LoginSignup
1
0

More than 3 years have passed since last update.

ServiceNow - 複数のスクリプトで共有する変数及び関数を定義する

Posted at

概要

複数のクライアントスクリプトで変数及び関数をする手順です。

onLoadスクリプト:グルーバル変数の宣言

共有する変数及び関数をOnLoadで宣言します。
onLoadスクリプトの「Isolate script」を無効にします。
image.png

var globalVar = "初期値"; // 共有変数

function onLoad() {

}

function sayHi(name) {  // 共有関数
    alert('Hi ' + name);
}

フィールド1のonChangeスクリプト:共有変数の値を変更

function onChange(control, oldValue, newValue, isLoading) {
    if (isLoading || newValue == '') {
        return;
    }
    globalVar = "フィールド1で変更。"; //共有変数の値を変更
}

フィールド2のonChangeスクリプト:グローバル変数を表示

function onChange(control, oldValue, newValue, isLoading) {
    if (isLoading || newValue == '') {
        return;
    }
    alert('変数の値:' + globalVar);  //共有変数の値を表示
    sayHi('Hitoshi'); //共有関数の呼び出し
}

実行結果

image.png
image.png

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