The Zurich release has arrived! Interested in new features and functionalities? Click here for more

Catalog item

ServiceNow40
Tera Contributor

Type : Select Box (field1) ,  Question name : operations , Choices : Companies , Activites , Opportunities.

Type : Select Box (field2), Question name : access , Choices : Read , Edit , Export , Explore , EPF.

 

If user select role is : Admin then field 1 : should be visible all choices,  field 2 select only visible those choices :Read , Edit ,EPF.

 

Any idea how to hide the choices.

 

Usint the Onchangescript but working any idea help me proper code.

2 REPLIES 2

Brad Bowman
Kilo Patron
Kilo Patron

Since this is a select box field you can use

 g_form.removeOption('field2_name', 'option value');

one line of code for each value to remove.  Be sure to use the select box choice value, not the label.  Is there a variable where a user can select the role admin, or are the choices dependent on the current user having the role of admin? If it's the latter you can use

if (g_user.hasRoleExactly('admin')) {

If you're still stuck, post your script attempt using the insert code icon </>, and we'll get it sorted.

debendudas
Mega Sage

You can refer the below onChange client script:

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

    var role = g_form.getValue("role");

    if (role == "admin") {
        g_form.removeOption("access", "Export");
        g_form.removeOption("access", "Explore");
    }else{
		g_form.addOption("access", "Export", "Export");
        g_form.addOption("access", "Explore", "Explore");
	}

}

 

If this solution helps you then, mark it as accepted solution ‌‌✔️ and give thumbs up 👍