Force Mandatory Variable
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-08-2023 02:37 PM - edited 11-08-2023 08:39 PM
Hi Connections,
I have a variable. Safe Updating with three choices, when safe updating is selected, I want to push user to fill any ONE of the below variables, Standard User Role OR Safe Manager Role. How can I achieve this. any suggestions... to show that two variables i have created UI policy to appear on the form when safe updating is selected....
appreciate any help.
Best Regards,
Rafmine.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-08-2023 08:50 PM
@Community Alums
update as this, you should use OR condition
function onSubmit() {
//Type appropriate comment here, and begin script below
var val = g_form.getValue('safeUpdatingVariable');
var userRole = g_form.getValue('userRoleVariable');
var managerRole = g_form.getValue('managerRoleVariable');
if(val == 'add user to sale value' && (userRole == '' || managerRole == '')){
alert('Kindly fill the Standard User Role Value & Safe Manager Role Value');
return false;
}
}
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-08-2023 09:32 PM
Hi @Community Alums
Jus a suggestion...!!
Best way is if possible then to create one new variable of type select box & depending upon the selection you can show the user role fields like below :
1.Select box with dropdown
2. On selection show the necessary fields
If user role selected
If manager role selected
ServiceNow Developer
I know one thing, and that is that I know nothing.
- Socrates
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-08-2023 10:22 PM
Hi Vishal,
I cannot create new variables, its not allowed... Your idea is best but my bad.... do you have second option?
Rafmine.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-08-2023 10:43 PM
Hi @Community Alums
Another workaround might be like this :
As you mentioned in your post , you have created ui policy to show both variable on form now try below :
1. Create onChange() client script on "Safe updating"
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
/*if Safe updating == Add user to safe then make both fields mandatory*/
if (newValue == 'add_user_to_safe'){
g_form.setMandatory('standard_user_role',true);
g_form.setMandatory('standard_manager_role',true);
} else {
g_form.setMandatory('standard_user_role',false);
g_form.setMandatory('standard_manager_role',false);
}
}
2.Create onChange() client script on Standard User role variable
function onChange(control, oldValue, newValue, isLoading) {
/*if user have entred some value in Standard user role variable then make Standard manager role variable mandatory as false*/
if (newValue != ''){
g_form.setMandatory('standard_manager_role',false);
} else {
g_form.setMandatory('standard_manager_role',true);
}
}
3.Create onChange() client script on Standard Manager role variable
function onChange(control, oldValue, newValue, isLoading) {
/*if user have entred some value in Standard manager role variable then make Standard user role variable mandatory as false*/
if (newValue != ''){
g_form.setMandatory('standard_user_role',false);
} else {
g_form.setMandatory('standard_user_role',true);
}
}
You can adjust the script as per your need as there might be contradiction.
Also use your backend name of variables whenever necessary.
Hope this helps...!!
ServiceNow Developer
I know one thing, and that is that I know nothing.
- Socrates