Issue with Onsubmit code client script,

David Cross
Tera Expert

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

4 REPLIES 4

Aman Kumar S
Kilo Patron

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.

https://www.servicenow.com/community/developer-blog/how-to-async-glideajax-in-an-onsubmit-script/ba-...

 

Best Regards
Aman Kumar

Sure  I'll go through and let u know

Aniket Narode2
Tera Contributor

Hello David,

Could you share script include code here just to check how you're sending response?

 

Thanks

Aniket

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

}