Abort client script onsubmit
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-02-2019 02:41 PM
Hi there,
i have the following script include:
and i have the following client script:
What i want is that if my script include return empty the client script abort and if its not empty the client script let the user submit the form. right now its working fine the include but there is something wrong with my client script as its always aborting with the line 13 in my code. any ideas?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-28-2020 11:51 PM
did the solution work ? i am also facing same issue in my script..
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-04-2021 07:24 AM
this is what worked for me, this is using the recommendations from above, applied as an OnSubmit catalog client script, the var_names are the "name" field of the variables. The below resulted in allowing the request to submit if one of the options is chosen, and blocked submission if not. If none were chosen, it displays a red alert message.
function onSubmit() {
//Type appropriate comment here, and begin script below
//This will check to see if any one of the variable checkboxes are checked
if(g_form.getValue("var_name1") == "false" && g_form.getValue("var_name2") == "false" && g_form.getValue("var_name3") == "false" && g_form.getValue("var_name4") == "false" && g_form.getValue("var_name5") == "false" && g_form.getValue("var_name6") == "false") {
g_form.addErrorMessage("Please select at least one option");
return false;
}
else return true;
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-05-2021 09:31 AM
if anyone else needs this... I like reusable code 🙂
Add Field "Data Loaded" with name "u_data_loaded" if you want the user to see.
client script:
function sleep(seconds) {
g_form.setValue('u_data_loaded', false); //OMIT IF NOT NEEDED
var ajax = new GlideAjax('sleepNow');
ajax.addParam('sysparm_name', 'sleep');
ajax.addParam('sysparm_seconds', 10);
ajax.getXML(checkit);
function checkit(response) {
var answer = response.responseXML.documentElement.getAttribute("answer");
alert("Loading of this week's data is complete.");
g_form.setValue('u_data_loaded', true); //OMIT IF NOT NEEDED
}
}
script include: (named - sleepNow)
var sleepNow = Class.create();
sleepNow.prototype = Object.extendsObject(AbstractAjaxProcessor, {
sleep: function() {
var sleepseconds = this.getParameter('sysparm_seconds') + '';
sleepseconds = parseInt(sleepseconds) * 1000;
gs.sleep(sleepseconds);
},
type: 'sleepNow'
});
I added a second onSubmit client script to prevent the user to be able to submit when it was still calculating.
function onSubmit() {
//Type appropriate comment here, and begin script below
var check = g_form.getValue('u_data_loaded') + '';
if(check == "false"){
alert("Sorry... still calculating time from tickets. Wait 5 seconds and try and save/update again.");
return false;
}
}