Catalog Client Script - onSubmit
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-21-2017 02:24 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-21-2017 02:57 AM
Please try the below script
var a = g_form.getValue('mouse');
var b = g_form.getValue(keyboard');
var c = g_form.getValue('headset');
if (a==no && b==no && c==no)
{
alert('Please select at least one accessory");
return false;
}
else
{
}
ServiceNow Commnunity MVP -2018 class.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-21-2017 02:59 AM
Modified...
function onSubmit() {
if(g_form.getValue('apns_mouse') == 'false' && g_form.getValue('apns_keyboard') == 'false' && g_form.getValue('apns_headset') == 'false' && g_form.getValue('docking_stations') == 'false')
{
//alert(g_form.getValue('contact_type'));
//g_form.setMandatory('assigned_to', true);
//Edited by Pushpanjali 21st July
alert("Please select atleast one accessory");
return false;
}
}
Regards,
Sadasiva
Please mark helpful/ correct based on the impact
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-25-2017 12:45 AM
Thank you for the above script.
It worked.
But I have one more query.
I have to write one more condition under present IF condition so that the Script does NOT only gets satisfied on YES/NO. It should work like if I have selected YES for MOUSE then I should select atleast one option also.
Right now what is happening is as soon as I am selecting YES for and accessory , I am able to add item in cart. It does not fulfills the requirement.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-25-2017 07:38 AM
Then you have those conditions also in the script.. modify below script as per ur requirement..
function onSubmit() {
if(g_form.getValue('apns_mouse') == 'false' && g_form.getValue('apns_keyboard') == 'false' && g_form.getValue('apns_headset') == 'false' && g_form.getValue('docking_stations') == 'false')
{
//alert(g_form.getValue('contact_type'));
//g_form.setMandatory('assigned_to', true);
//Edited by Pushpanjali 21st July
alert("Please select atleast one accessory");
return false;
}
else{
if(g_form.getValue('apns_mouse') == 'true' ){
if(g_form.getValue('mouse_1') == 'false' &&g_form.getValue('mouse_2') == 'false' &&g_form.getValue('mouse_3') == 'false' ){
alert("Please select atleast one accessory");
return false;
}
if(g_form.getValue('apns_keyboard') == 'true' ){
if(g_form.getValue('keyboard_1') == 'false' &&g_form.getValue('keyboard_2') == 'false' &&g_form.getValue('keyboard_3') == 'false' ){
alert("Please select atleast one accessory");
return false;
}
// do the same thing for remaining like headset etc....
}
}
}
Regards,
Sadasiva
Please mark helpful/ correct based on the impact