Abort client script onsubmit

Mr Bow
Kilo Expert

Hi there,

i have the following script include:

 

 

find_real_file.png

 

and i have the following client script: 

find_real_file.png

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?

 

12 REPLIES 12

Tanuj8
Kilo Contributor

did the solution work ? i am also facing same issue in my script..

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;

}

TimW1
Tera Expert

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;
}
}