0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Record Producer 9:Record Producer のg_formについて【ServiceNow】

Posted at

※この記事はServiceNow初心者が学習用のために記載した記事です。内容について誤っている場合がございます。不足点などございましたらコメントいただけますと幸いです。

g_formとは

  • Record Producerのg_form は、ServiceNowのクライアントサイドで動作するスクリプト(特に、Catalog Client Script や Client Script)内で使用されるオブジェクト
  • フォームに表示されているフィールドの値を操作したり、フォームの動作を制御したりできる
  • g_form メソッドの第1引数 は、Record Producer の Variables の name フィールド を指す
  • g_form の第2引数 は、操作対象のフィールドに対する特定のアクションを実行するための追加パラメータを指す

g_formの役割

  • g_formは、フォーム上のフィールドにアクセスして制御を行うためのAPIを提供
  • Record Producerでは、これを使ってユーザーが入力した情報に基づいてフォームを動的に操作できる

主な機能

フィールドの表示・非表示制御

  • g_form.setDisplay('フィールド名', true/false) を使用して、フォームのフィールドを表示または非表示にできる
  • 例:
    g_form.setDisplay('phone', false); // phoneフィールドを非表示
    

フィールドの値を取得・設定

  • g_form.getValue('フィールド名') でフィールドの値を取得
  • g_form.setValue('フィールド名', 値) でフィールドの値を設定
  • 例:
    var phone = g_form.getValue('phone'); // 'phone' フィールドの値を取得
    g_form.setValue('address', '新しい住所'); // 'address' フィールドの値を設定
    

フィールドの読み取り専用/編集可能設定

  • g_form.setReadOnly('フィールド名', true/false) でフィールドを読み取り専用にするか、編集可能にする
  • 例:
    g_form.setReadOnly('phone', true); // phoneフィールドを読み取り専用にする
    

フィールドの必須設定

  • g_form.setMandatory('フィールド名', true/false) でフィールドを必須にするか、必須解除を制御する
  • 例:
    g_form.setMandatory('address', true); // 'address' フィールドを必須にする
    

フィールドの値に基づくアクションの実行

  • 特定のフィールドの値を監視し、変更されたときにアクションを実行できます。たとえば、別のフィールドを表示したり、非表示にしたりできる

Record Producerにおけるg_formの使用例

フィールドの表示・非表示の制御:

Record Producerを使用して、特定の条件に応じてフィールドを表示または非表示にすることができる

function onLoad() {
    var selectedOption = g_form.getValue('category');
    if (selectedOption == '特定のカテゴリ') {
        g_form.setDisplay('subcategory', true);  // 'subcategory' フィールドを表示
    } else {
        g_form.setDisplay('subcategory', false); // 'subcategory' フィールドを非表示
    }
}

ユーザー入力に基づく処理:

Record Producerフォームに入力された情報を基に、他のフィールドを自動的に設定することができる

function onChange(control, oldValue, newValue, isLoading) {
    if (newValue == '特定のオプション') {
        g_form.setValue('priority', '');  // 'priority' フィールドに '高' を設定
    }
}
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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?