階層選択フィールの作成


概要

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

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

実装

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

変数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 '
});

上のコードを実装すると次のように子会社がリストコレクタに選択される。

しかし、ユーザはまだ登録されている会社すべてを選択することが可能。

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

指定すると子会社のみ選択可能になる。