None option for a drop down
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-08-2024 07:51 PM
Hi,
How to change the code for the None option to work? The rest of the options are good.
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
var status = g_form.getValue('u_state');
if(status == 'new'){
g_form.setMandatory('u_in_progress_status', false);
g_form.setMandatory('u_resolved_status', false);
g_form.setMandatory('u_canceled_status', false);
g_form.setVisible('u_new_status', true);
g_form.setMandatory('u_new_status', true);
g_form.setDisplay('u_in_progress_status', false);
g_form.setDisplay('u_resolved_status', false);
g_form.setDisplay('u_canceled_status', false);
}
if(status == 'in_progress'){
g_form.setMandatory('u_new_status', false);
g_form.setMandatory('u_resolved_status', false);
g_form.setMandatory('u_canceled_status', false);
g_form.setVisible('u_in_progress_status', true);
g_form.setMandatory('u_in_progress_status', true);
g_form.setDisplay('u_new_status', false);
g_form.setDisplay('u_resolved_status', false);
g_form.setDisplay('u_canceled_status', false);
}
if(status == 'resolved'){
g_form.setMandatory('u_new_status', false);
g_form.setMandatory('u_in_progress_status', false);
g_form.setMandatory('u_canceled_status', false);
g_form.setVisible('u_resolved_status', true);
g_form.setMandatory('u_resolved_status', true);
g_form.setDisplay('u_new_status', false);
g_form.setDisplay('u_in_progress_status', false);
g_form.setDisplay('u_canceled_status', false);
}
if(status == 'Canceled'){
g_form.setMandatory('u_new_status', false);
g_form.setMandatory('u_in_progress_status', false);
g_form.setMandatory('u_resolved_status', false);
g_form.setVisible('u_canceled_status', true);
g_form.setMandatory('u_canceled_status', true);
g_form.setDisplay('u_new_status', false);
g_form.setDisplay('u_in_progress_status', false);
g_form.setDisplay('u_resolved_status', false);
}
// if((status != 'new') && (status != 'in_progress') && (status != 'resolved') && (status != 'Canceled'){
// g_form.setMandatory('u_new_status', false);
// g_form.setMandatory('u_in_progress_status', false);
// g_form.setMandatory('u_resolved_status', false);
// g_form.setMandatory('u_canceled_status', false);
// g_form.setDisplay('u_in_progress_status', false);
// g_form.setDisplay('u_resolved_status', false);
// g_form.setDisplay('u_canceled_status', false);
// g_form.setDisplay('u_new_status', false);
// }
}
In the picture you can see the New status is not getting removed when I change the status to None.
Regards
Suman P.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-09-2024 02:08 AM - edited 11-09-2024 02:15 AM
Hello @Community Alums
Servicenow recommend to use ootb functionality and follow low code approach, just for improving the skills in scripting replace the commented line with:
Condition can be ignored as there is no other options.
else {
g_form.setMandatory('u_in_progress_status', false);
g_form.setMandatory('u_resolved_status', false);
g_form.setMandatory('u_canceled_status', false);
g_form.setDisplay('u_in_progress_status', false);
g_form.setDisplay('u_resolved_status', false);
g_form.setDisplay('u_canceled_status', false);
g_form.setDisplay('u_new_status', false);
}
*************************************************************************************************************
"If you found my answer helpful, please give it a like and mark it as the "accepted solution". It helps others find the solution more easily and supports the community!"
Thank You
Juhi Poddar
****************************************************************************************************************
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-09-2024 01:51 AM
Hi @Community Alums ,
Couple of thing to note.
- Make sure you are using exact filed name and value to compare.
- When ever you are hiding field first you make that filed non mandatory and then hide.
- You have not written any else condition that check if state is empty then make field non mandatory and hidden.
Use below case
var status = g_form.getValue('u_state');
if(status == 'new'){
g_form.setMandatory('u_in_progress_status', false);
g_form.setMandatory('u_resolved_status', false);
g_form.setMandatory('u_canceled_status', false);
g_form.setVisible('u_new_status', true);
g_form.setMandatory('u_new_status', true);
g_form.setDisplay('u_in_progress_status', false);
g_form.setDisplay('u_resolved_status', false);
g_form.setDisplay('u_canceled_status', false);
}else if(status == 'in_progress'){
g_form.setMandatory('u_new_status', false);
g_form.setMandatory('u_resolved_status', false);
g_form.setMandatory('u_canceled_status', false);
g_form.setVisible('u_in_progress_status', true);
g_form.setMandatory('u_in_progress_status', true);
g_form.setDisplay('u_new_status', false);
g_form.setDisplay('u_resolved_status', false);
g_form.setDisplay('u_canceled_status', false);
}else if(status == 'resolved'){
g_form.setMandatory('u_new_status', false);
g_form.setMandatory('u_in_progress_status', false);
g_form.setMandatory('u_canceled_status', false);
g_form.setVisible('u_resolved_status', true);
g_form.setMandatory('u_resolved_status', true);
g_form.setDisplay('u_new_status', false);
g_form.setDisplay('u_in_progress_status', false);
g_form.setDisplay('u_canceled_status', false);
}else if(status == 'Canceled'){
g_form.setMandatory('u_new_status', false);
g_form.setMandatory('u_in_progress_status', false);
g_form.setMandatory('u_resolved_status', false);
g_form.setVisible('u_canceled_status', true);
g_form.setMandatory('u_canceled_status', true);
g_form.setDisplay('u_new_status', false);
g_form.setDisplay('u_in_progress_status', false);
g_form.setDisplay('u_resolved_status', false);
}else{
g_form.setMandatory('u_new_status', false);
g_form.setMandatory('u_in_progress_status', false);
g_form.setMandatory('u_resolved_status', false);
g_form.setMandatory('u_canceled_status', false);
g_form.setDisplay('u_in_progress_status', false);
g_form.setDisplay('u_resolved_status', false);
g_form.setDisplay('u_canceled_status', false);
g_form.setDisplay('u_new_status', false);
}
Note: Also better you can use UI Policy for this.
-------------------------------------------------------------------------
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
-------------------------------------------------------------------------