Based on user location remove options

Vinya Jakkula
Tera Contributor

Hi Team help me!!

I have a reference field which is opened for?

based on user location I need to remove options?

 

4 REPLIES 4

Deepak Shaerma
Kilo Sage
Kilo Sage

Hi @Vinya Jakkula 
can you explain, what is the field type from which you need to remove the options. 
Explain to solve it efficiently.
Please Mark this Helpful and Accepted Solution. If this Helps you to understand. This will help both the community and me..
- Keep Learning ‌‌
Thanks & Regards 
Deepak Sharma 

@Deepak Shaerma  It is select box.

Deepak Shaerma
Kilo Sage
Kilo Sage

Hi @Vinya Jakkula 
Common approach for removing the field value based on user location is mostly fulfilled by both server side and client side scripting. in your case i provide on change client script 
On Change for Req for

if (newValue) {
        var userGR = new GlideRecord('sys_user'); // Adjust ‘sys_user’ if your user table has a different name or sys_id needs to be queried from another table.
        userGR.get(newValue); // Here, newValue is the sys_id of the selected caller
        if (userGR.location == 'sys_id_of_Location_A') { // Replace ‘sys_id_of_Location_A’ with the actual sys_id of Location A.
            // Now remove the option from the select box
            var selectBox = g_form.getGlideUIElement('your_select_box_field'); // replace ‘your_select_box_field’ with the actual field name
            if (selectBox) {
                selectBox.removeOption('value_of_option_A'); // Replace ‘value_of_option_A’ with the value of the option you want to remove
            }
        }
    }

Please Mark this Helpful and Accepted Solution. If this Helps you to understand. This will help both the community and me..
- Keep Learning ‌‌
Thanks & Regards 
Deepak Sharma 

Ankur Bawiskar
Tera Patron
Tera Patron

@Vinya Jakkula 

you can write onChange + getReference callback and get the location and then remove the options using

g_form.removeOption('fieldName', 'choiceValue');

what script did you start with and where are you stuck?

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader