Issue with Onsubmit code client script,
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-27-2023 01:50 AM
Hello All,
I have issue with my onsubmit client script, it's returning the value even if it's false...
Here if the attachment is not added then it should go to false.. But instead in the alert I can always see true...
Can you please check my code and please suggest me what to do -> attachment added

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-27-2023 01:53 AM
Hi @David Cross ,
Since you are using async ajax in a onsubmit client script, it will not work out.
You can follow below article to learn ways how to achieve this.
Aman Kumar
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-27-2023 03:01 AM
Sure I'll go through and let u know
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-27-2023 01:58 AM
Hello David,
Could you share script include code here just to check how you're sending response?
Thanks
Aniket
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-27-2023 10:29 PM
Hello Aniket, I'm sorry for a delay in reply, I was off screen for a while. Below is my code
function onSubmit() {
var ass = g_form.getValue('assignment_group');
var sysid = g_form.getUniqueValue();
var rValue = true;
var ga = new GlideAjax('AttachmentAjax');
ga.addParam('sysparm_type', 'attachmentCount');
ga.addParam('sysparm_value', sysid);
ga.getXMLAnswer(numberOfAttachments, null, sysid);
function numberOfAttachments(answer, sysid) {
var jsonUser = JSON.parse(answer);
if (ass == '61a7a5f0db9b901004f6e16c0b9619f5') {
if (jsonUser == '0') {
alert(jsonUser);
rValue = false;
}
}
alert(rValue);
return rValue;
}
}