LoginSignup
0
0

More than 3 years have passed since last update.

ServiceNow - 階層選択フィールの作成

Posted at

概要

参照フィールドの選択に基づいて他選択フィールドの内容を変える

今回の例では「会社」参照フィールドで選択された子会社をリストコレクタかから選択可能にする

実装

次のように参照型とリストコレクタの変数を定義する。
subsidiary_1_20201022.png

subsidiary_2_20201022.png

変数vrm_vendor_lookupのonChangeスクリプト

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

    var vendorGA = new GlideAjax('GetVendorLocations');
    vendorGA.addParam('sysparm_name', 'get_locations');
    vendorGA.addParam('sysparm_vendor_id', newValue);
    vendorGA.getXMLAnswer(function(answer) {
        var subsidiary  = JSON.parse(answer);
        g_form.setValue('vrm_new_satellite_existing_location', subsidiary);
    });
}

スクリプトインクルード

var GetVendorLocations = Class.create();
GetVendorLocations.prototype = Object.extendsObject(AbstractAjaxProcessor, {

    get_locations: function() {

        var locations = [];
        var vendorID = this.getParameter('sysparm_vendor_id');

        var satelliteOffice = new GlideRecord('core_company');
        satelliteOffice.addQuery('parent.sys_id', vendorID);
        //satelliteOffice.addQuery('vendor', true);
        satelliteOffice.query();
        gs.log('Denis has this ID ' + vendorID);
        while (satelliteOffice.next()) {

            locations.push(satelliteOffice.sys_id.toString());
        }
        return JSON.stringify(locations);
    },

    type: 'GetVendorLocations '
});

上のコードを実装すると次のように子会社がリストコレクタに選択される。
subsidiary_3_20201022.png
しかし、ユーザはまだ登録されている会社すべてを選択することが可能。
subsidiary_4_20201022.png

子会社のみ選択可能にするにはReference qualifierを指定する。
subsidiary_5_20201022.png

指定すると子会社のみ選択可能になる。
subsidiary_6_20201022.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