Catalog Client Script - onSubmit

pushpanjalichau
Giga Contributor

I want to write an onSubmit Catalog Client Script so that out of 3 options User has to select atleast one.

If the user has not selected any option and tries to Add Item in the Cart then a message should display like "Please select atleast one accessory."

find_real_file.png

8 REPLIES 8

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


{


}


Karthik Reddy T.
ServiceNow Commnunity MVP -2018 class.

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


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.



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