Assignment group read only
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-28-2024 12:23 PM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-29-2024 12:22 AM
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);
}
Assignment group is read only for ITIL user.
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
-------------------------------------------------------------------------
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-29-2024 06:09 AM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-29-2024 07:09 AM
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
-------------------------------------------------------------------------