- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-13-2023 12:33 AM
Hi All,
I have created a on submit client script if the condition is matched it should give alert message and abort action i have used return false but still form is getting submitted what could be the possible issue and how to fix it, please share if anyone has pointers on this.
Thanks in advance.
Kruthik Shivaprasad
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-13-2023 02:41 AM
Add one more line "return false" to the bottom of the client script. It should work
function onSubmit() {
/*** Pop this gem into your script! */
if (g_scratchpad.isFormValid) {
return true;
}
var actionName = g_form.getActionName();
var ga = new GlideAjax('x_intellectu.CheckRetired');
ga.addParam('sysparm_name', 'CheckingRetired');
ga.addParam('sysparm_ia_name', g_form.getValue('ia_name'));
ga.getXML(RetiredCheck);
function RetiredCheck(response) {
var answer = response.responseXML.documentElement.getAttribute("answer");
if (answer == 'true') {
alert('This is retired');
return false;
}
/*** Pop this gem into your script! */
g_scratchpad.isFormValid = true;
g_form.submit(actionName);
}
/*** Pop this gem into your script! */
return false;
}
Cheers,
Tai Vu
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-13-2023 01:24 AM
Hi @Tai Vu
tried this code but still getting submitted
Thank you
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-13-2023 02:20 AM
Did it come to the IF Condition with the alert?
We need to check what was this function return in your test case. => CheckingRetired
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-13-2023 02:27 AM
It is returning true in our case.
var CheckRetired = Class.create();
CheckRetired.prototype = Object.extendsObject(global.AbstractAjaxProcessor, {
CheckingRetired:function(){
var found;
var ianame = this.getParameter("sysparm_ia_name");
var dup = new GlideRecord('x_infte_ia');
dup.addQuery('asset_name', ianame);
dup.query();
if(dup.next()){
if(dup.status==6){
found = 'true';
}
else{
found = 'false';
}
}
return found;
},
type: 'CheckRetired'
});
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-13-2023 02:41 AM
Add one more line "return false" to the bottom of the client script. It should work
function onSubmit() {
/*** Pop this gem into your script! */
if (g_scratchpad.isFormValid) {
return true;
}
var actionName = g_form.getActionName();
var ga = new GlideAjax('x_intellectu.CheckRetired');
ga.addParam('sysparm_name', 'CheckingRetired');
ga.addParam('sysparm_ia_name', g_form.getValue('ia_name'));
ga.getXML(RetiredCheck);
function RetiredCheck(response) {
var answer = response.responseXML.documentElement.getAttribute("answer");
if (answer == 'true') {
alert('This is retired');
return false;
}
/*** Pop this gem into your script! */
g_scratchpad.isFormValid = true;
g_form.submit(actionName);
}
/*** Pop this gem into your script! */
return false;
}
Cheers,
Tai Vu
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-13-2023 01:01 AM
Hi Jaspal,
Please find below script the alert is coming when clicked on submit but once click on ok on that popup the form is getting submitted.