Hide/Display fields in the modal(g_modal.showFields) for Suspend ( HR case) and Suspend case( HR task) UI action in HR Agent workspace.

Pooja Kulkarni
Tera Contributor

Hello,

We have customized the UI page 'HR Suspend Dialog' which is being called from the 'Suspend' and 'Suspend case' UI action. As per the customization, Work notes field is NOT displayed always. It is displayed only when certain suspension reason is selected. We want the same functionality in HR Agent workspace as well.

If we look into the OOTB code for workspace , Work notes field has been defaulted and displayed always with below code:

https://devxxxx.service-now.com/sys_ui_action.do?sys_id=b65370019f22120047a2d126c42e701d&sysparm_view=&sysparm_record_target=sys_ui_action&sysparm_record_row=1&sysparm_record_list=sys_id%3Db65370019f22120047a2d126c42e701d%5EORDERBYorder&sysparm_record_rows=1


find_real_file.png
I want to display work notes field only when certain reason is selected. Please advice.

1 ACCEPTED SOLUTION

Muhammad Khan
Mega Sage
Mega Sage

Hi Pooja,

 

Consider it as a workaround to fulfill your requirement. You can try to show two modals

  1. Take Reason
  2. Take Work Notes

When user has provided the reason for which you want to show the work notes field, show another modal to take work notes from user. See the below script for reference.

function onClick(g_form) {

    var type = [{
        type: 'choice',
        name: 'u_type',
        label: 'New Type',
        mandatory: true,
        value: getMessage(' -- Select -- '),
        choices: [{
                displayValue: 'Best',
                value: 'Best'
            },
            {
                displayValue: 'Bad',
                value: 'Bad'
            }
        ]
    }];

    var workNote = [{
        type: 'textarea',
        name: 'work_notes',
        label: 'New Type',
        mandatory: true,
        value: getMessage('Work notes')
    }];


    g_modal.showFields({
        title: 'Enter New Values',
        fields: type,
        size: 'lg',
        height: 'md'
    }).then(function(selectedType) {

        if (selectedType.updatedFields[0].value == 'Best') {
            g_modal.showFields({
                title: 'Enter New Values',
                fields: workNote,
                size: 'lg',
                height: 'md'
            }).then(function(newWorkNote) {
                g_form.setValue('u_type', selectedType.updatedFields[0].value);
                g_form.setValue('work_notes', newWorkNote.updatedFields[0].value);
                g_form.save();

            });

        } else {
            g_form.setValue('u_type', selectedType.updatedFields[0].value);
            g_form.save();
        }

    });

}

View solution in original post

9 REPLIES 9

Muhammad Khan
Mega Sage
Mega Sage

Hi Pooja,

 

Consider it as a workaround to fulfill your requirement. You can try to show two modals

  1. Take Reason
  2. Take Work Notes

When user has provided the reason for which you want to show the work notes field, show another modal to take work notes from user. See the below script for reference.

function onClick(g_form) {

    var type = [{
        type: 'choice',
        name: 'u_type',
        label: 'New Type',
        mandatory: true,
        value: getMessage(' -- Select -- '),
        choices: [{
                displayValue: 'Best',
                value: 'Best'
            },
            {
                displayValue: 'Bad',
                value: 'Bad'
            }
        ]
    }];

    var workNote = [{
        type: 'textarea',
        name: 'work_notes',
        label: 'New Type',
        mandatory: true,
        value: getMessage('Work notes')
    }];


    g_modal.showFields({
        title: 'Enter New Values',
        fields: type,
        size: 'lg',
        height: 'md'
    }).then(function(selectedType) {

        if (selectedType.updatedFields[0].value == 'Best') {
            g_modal.showFields({
                title: 'Enter New Values',
                fields: workNote,
                size: 'lg',
                height: 'md'
            }).then(function(newWorkNote) {
                g_form.setValue('u_type', selectedType.updatedFields[0].value);
                g_form.setValue('work_notes', newWorkNote.updatedFields[0].value);
                g_form.save();

            });

        } else {
            g_form.setValue('u_type', selectedType.updatedFields[0].value);
            g_form.save();
        }

    });

}

Hi @Muhammad Khan , We are trying to implement it for a Date field, Is there any way to get Date field in Glide modal ?

find_real_file.png

Hi, you can update the input element type to date(type="date") in the UI Page HTML code.

 

Hi Vamis,

We are trying to implement this in workspace client script of the UI Action using g_modal method, not in the UI Page