- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-17-2017 10:49 AM
hi all,
I have a javascript question. I have an onSubmit catalog client script to prevent submission of a record producer if the user has not checked a box on the form. This is working properly. However I need this to only apply if another field on the form is set a certain way. Right now here is my script:
function onSubmit() {
if(g_form.getValue('ad_domain') == 'YES'){
return true;
}
if(g_form.getValue(user_confirm') == 'false' ){
alert('Please be sure to check the box before submitting a ticket.');
return false;
}
}
this part is working properly:
if(g_form.getValue(user_confirm') == 'false' ){
alert('Please be sure to check the box before submitting a ticket.');
return false;
but it's the first "if" part that I need to tweak, I only want the script to fire if the field on the form "ad_domain" is set to YES. If this field is set to NO I don't want the script to fire.
how do I do this? thanks!
Solved! Go to Solution.
- Labels:
-
Service Catalog
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-17-2017 02:40 PM
While that solution works, it's not very user friendly. Why have them submit, then cancel and require them to click a checkbox. You should make their life easier...I'm not sure what this checkbox is, but you have several options:
1) This is the best user experience and what you should be doing... Create a UI policy ...under When to Apply...Add Filter Conition ad_domain = YES or ad_comain=YesB and question_choide = incorrect info. Leave Reverse if False...then Save. After it reloads go to UI Policy Actions, select new, add in the checkbox field and set Mandatory to true. This will pre-empt the user to check it prior to submission. to inform them after submission is the least desirable as it adds clicks...Submit -> Ok on alert -> check box -> Submit and hope you don't rinse repeat due to other onSubmits...
2) If you can't do that for some reason, then don't hate on your users and require them to check a box then have to resubmit... use a confirm and do it for them...
function onSubmit() {
if(g_form.getValue('ad_domain') == 'YES' || g_form.getValue('ad_domain') == 'YESb' && g_form.getValue('question_choice') == 'incorrect info' ) //assuming values are YES and YESb
{
if(g_form.getValue('user_confirm') == 'false' ){
var result = confirm('Are you sure you wish to submit?');//or whatever that checkbox is for
if (result) {
g_form.setValue('checkbox', true);
else
return false;
}
}
}
*edit: changed prompt to confirm*

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-17-2017 11:24 AM
Replace this line if(g_form.getValue('ad_domain') == 'YES' || g_form.getValue('ad_domain') == 'NO' && g_form.getValue('question_choice') == 'incorrect info' ){ //assuming values are YES and NO with
if(g_form.getValue('ad_domain') == 'YES' || g_form.getValue('ad_domain') == 'YESb' && g_form.getValue('question_choice') == 'incorrect info' ){ //assuming values are YES and YESb

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-17-2017 11:24 AM
function onSubmit() {
alert(g_form.getValue('ad_domain')); //To make sure value is YES. This is just for tesiting purpose.
if((g_form.getValue('ad_domain') == 'YES' || g_form.getValue('ad_domain') == 'YESb') && g_form.getValue('question_choice') == 'incorrect info' ){
if(g_form.getValue(user_confirm') !=true ){
alert('Please be sure to check the box before submitting a ticket.');
return false;
}
}
}
Please mark this response as correct or helpful if it assisted you with your question.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-17-2017 11:23 AM
also, how do I make this character "||"?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-17-2017 11:25 AM
Should be above your Enter key
Please mark this response as correct or helpful if it assisted you with your question.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-17-2017 11:30 AM
You can just copy and paste the below code
function onSubmit() {
//Type appropriate comment here, and begin script below
alert(g_form.getValue('ad_domain')); //To make sure value is YES. This is just for tesiting purpose.
if(g_form.getValue('ad_domain') == 'YES' || g_form.getValue('ad_domain') == 'YESb' && g_form.getValue('question_choice') == 'incorrect info' ) //assuming values are YES and YESb
{
if(g_form.getValue('user_confirm') == 'false' ){
alert('Please be sure to check the box before submitting a ticket.');
return false;
}
}
}