- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-24-2017 07:32 AM
Hi All,
I am having an onSubmit Catalog Client Script on Service portal to prevent it from Submitting without Subcategory2 value, But it is not working.
And also I have tried the same using GlideAjax, that is also failing...
Please find my code below,
Title: Catalog Client Script
function onSubmit() {
function onSubmit() {
//Type appropriate comment here, and begin script below
var form = typeof g_sc_form != "undefined" ? g_sc_form : g_form;
var subCat1Value = g_form.getValue('u_subcategory');
var subCat2Value = form.getValue('u_subcategory_2');
var gp = new GlideRecord('sys_choice');
gp.addQuery('name', 'change_request');
gp.addQuery('dependent_value', subCat1Value);
gp.addQuery('element', 'u_subcategory_2');
gp.addQuery('inactive', 'false');
gp.query(function(gp) {
if(!gp.hasNext()){
return true;
}
if(gp.hasNext() && subCat2Value == 'none'){
alert('Please select atleast one value from Subcagtegory 2');
return false; // The code automatically get submitted without a Subcategory2 value after getting above mentioned alert
}
} );
}
}
} );
}
Can anyone help me..
Thanks In advance.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-26-2017 02:53 AM
The following code has worked for me...
function onSubmit() {
//Type appropriate comment here, and begin script below
if (!window) {
if (g_scratchpad.isFormValid) {
return true;
}
var form = typeof g_sc_form != "undefined" ? g_sc_form : g_form;
var subCat1Value = g_form.getValue('u_subcategory');
var subCat2Value = form.getValue('u_subcategory_2');
var gp = new GlideRecord('sys_choice');
gp.addQuery('name', 'change_request');
gp.addQuery('dependent_value', subCat1Value);
gp.addQuery('element', 'u_subcategory_2');
gp.addQuery('inactive', 'false');
gp.query(function(gp) {
if(gp.getRowCount() >= 1 && subCat2Value == 'none'){
alert('Please select atleast one value from Subcagtegory 2');
return false;
}
g_scratchpad.isFormValid = true;
g_form.submit();
});
return false;
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-24-2017 07:44 AM
Could it be this line? you're missing 'g_'
var subCat2Value = g_form.getValue('u_subcategory_2');
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-24-2017 08:06 AM
Hi All,
Thank you all for your response.
I am able to get the values and control is going inside and getting the alert "Please select at lease one value from Subcagtegory 2".
But my problem is after getting the alert the record getting submitted automatically with out Subcategory2 chosen.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-24-2017 08:29 AM
Hi Silva,
Have you tried Synchronous Glide Ajax?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-24-2017 09:00 AM
Hi Midhun Golla,
Thanks for your response,
Yeah I have tried both Synchronous and Asynchronous Glide Ajax.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-26-2017 02:53 AM
The following code has worked for me...
function onSubmit() {
//Type appropriate comment here, and begin script below
if (!window) {
if (g_scratchpad.isFormValid) {
return true;
}
var form = typeof g_sc_form != "undefined" ? g_sc_form : g_form;
var subCat1Value = g_form.getValue('u_subcategory');
var subCat2Value = form.getValue('u_subcategory_2');
var gp = new GlideRecord('sys_choice');
gp.addQuery('name', 'change_request');
gp.addQuery('dependent_value', subCat1Value);
gp.addQuery('element', 'u_subcategory_2');
gp.addQuery('inactive', 'false');
gp.query(function(gp) {
if(gp.getRowCount() >= 1 && subCat2Value == 'none'){
alert('Please select atleast one value from Subcagtegory 2');
return false;
}
g_scratchpad.isFormValid = true;
g_form.submit();
});
return false;
}
}