Assignment group read only

DSV22
Tera Contributor

Hi Team,

 

I have to make assignment group (which is mandatory) read only, based on the a choice field and the roles of a user i.e..,

 

I have field named "desk" with 3 choices "it", "hr", "dat entry" and the field will be populated with "it" when the form loads, I have to make assignment group read only when the "desk is "it" and assignment group should be editable by Admin and itil admin users. When users select another choice of the field 

 

 

I have tried using ui policies and client script but not working, can anyone help me out to achieve this.

 

 

Thanks in advance

 

7 REPLIES 7

Runjay Patel
Giga Sage

Hi @DSV22 ,

 

You can create onchange client script.

 

use below code, i have tested it. working as expected.

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
    
	 var role = g_user.hasRole('itil_admin');

	if (isLoading || newValue === '') {
        if (newValue == 'it') {

       
        if (!role) {
            g_form.setReadOnly('assignment_group', true);
        } else
            g_form.setReadOnly('assignment_group', false);
    } else
        g_form.setReadOnly('assignment_group', false);
    }

    if (newValue == 'it') {

       
        if (!role) {
            g_form.setReadOnly('assignment_group', true);
        } else
            g_form.setReadOnly('assignment_group', false);
    } else
        g_form.setReadOnly('assignment_group', false);


}

 

RunjayPatel_0-1730186474291.png

 

 

Assignment group is read only for ITIL user.

RunjayPatel_1-1730186522136.png

 

Note: If assignment group is mandatory in your case then before making readonly you need to first make it non mandatory.

 

-------------------------------------------------------------------------

If you found my response helpful, please consider selecting "Accept as Solution" and marking it as "Helpful." This not only supports me but also benefits the community.


Regards
Runjay Patel - ServiceNow Solution Architect
YouTube: https://www.youtube.com/@RunjayP
LinkedIn: https://www.linkedin.com/in/runjay

-------------------------------------------------------------------------

 

 

 

HI @Runjay Patel ,

 

your solution had worked in making the assignment group read only but making it mandatory for other choices is not working i have done exactly what you mentioned in the note.

Hi @DSV22 ,

 

Use below code to make mandatory if Desk not selected as IT.

 

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
    
	 var role = g_user.hasRole('itil_admin');

	if (isLoading || newValue === '') {
        if (newValue == 'it') {

       
        if (!role) {
            g_form.setReadOnly('assignment_group', true);
        } else
            g_form.setReadOnly('assignment_group', false);
    } else
        g_form.setReadOnly('assignment_group', false);
    }

    if (newValue == 'it') {

       
        if (!role) {
            g_form.setReadOnly('assignment_group', true);
        } else
            g_form.setReadOnly('assignment_group', false);
    } else{
        g_form.setReadOnly('assignment_group', false);
g_form.setMandatory('assignment_group', true);


}

}

 

one line of code you need add.

 

-------------------------------------------------------------------------

If you found my response helpful, please consider selecting "Accept as Solution" and marking it as "Helpful." This not only supports me but also benefits the community.


Regards
Runjay Patel - ServiceNow Solution Architect
YouTube: https://www.youtube.com/@RunjayP
LinkedIn: https://www.linkedin.com/in/runjay

-------------------------------------------------------------------------