UI modal - make a choice field non read only based on another choice field value present on the form

sharan16
Tera Contributor

I have a requirement to make a choice field on the UI modal to be editable only when another choice field in the form has one particular value.  (Approval is the field on the form -> The field on the UI modal is Approval type. Approval type should be editable only when Approval field value is 'Approved' and read only for other choices.

 

UI modal workspace client script:

 

 var getChoices = new GlideAjax("scriptincludename");
    getChoices.addParam('sysparm_name', 'getChoicesValue');
    getChoices.getXMLAnswer(callBack);
 
    function callBack(answer) {
        var suspendValue = g_form.getValue('approval_type');
        var reasons = JSON.parse(answer);

            g_modal.showFields({
            title: 'Send for approval',
            fields: [
                {
                    type: 'glide_list',
                    name: 'additional_approvers',
                    label: 'Additional approvers',
                    mandatory: true,
                    referringTable: 'change_request',
                    referringRecordId: '-1',
                    dictionary: {
                        reference: 'sys_user'
                    },
                },
                {
                    type: 'choice',
                    name: 'reasonChoice',
                    label: 'Approval Type',
                    value: suspendValue ? suspendValue : '',
                    choices: reasons,
                    readonly:suspendValue ? true : false,
                    mandatory:suspendValue? false: true,
                },
            ],
            size: 'md'
 
Script include:
    getChoicesValue: function() {
        var reasons = [];
        var choiceList = GlideChoiceList.getChoiceList('incident', 'approval_type');
        choiceList.removeNone();
        for (var i = 0; i < choiceList.getSize(); i++) {
            var choice = choiceList.getChoice(i);
            gs.info("Check>>> " + choiceList.getChoice(i));

            reasons.push({
                displayValue: choice.label.toString(),
                value: choice.value.toString()
            });
        }
        return JSON.stringify(reasons);

    },
 
Currently the script i have written makes the Approval type field on the UI modal window - always read-only
Is there any way to make it editable on certain conditions?
0 REPLIES 0