The CreatorCon Call for Content is officially open! Get started here.

on submit client script is not working

chandan2212
Tera Contributor

Hi All, 

 

onsubmit client script is not working 

function onSubmit() {
  var gr = g_form.getValue('action');
  
  if (gr === 'sharing') {
    alert('Chandan Patra');
    return false; // Prevents form submission
  }

  return true; // Allows form submission
}

 Thanks and Regards,

Chandan 

5 REPLIES 5

RaghavSh
Kilo Patron

Avoid using gr as variable.

 

what is action here, is it a field name?

 

Remove return=true; there is no need for that statement.


Raghav
MVP 2023
LinkedIn

@chandan2212 Did this work for you?


Please mark the answer correct/helpful accordingly.


Raghav
MVP 2023
LinkedIn

Ankur Bawiskar
Tera Patron
Tera Patron

@chandan2212 

are you comparing correct value for action in your IF

💡 If my response helped, please mark it as correct ✔️ and close the thread 🔒 — this helps future readers find the solution faster! 🙏

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

kaushal_snow
Mega Sage

@chandan2212 ,

 

onSubmit client script like yours, may not run (or its return false may be ignored) if there's another conflicting onSubmit script, UI policy, or asynchronous logic (such as a GlideAjax call) that causes the form to bypass or override the client script, so check whether, another onSubmit client script exists....then script UI Type is set correctly (Desktop / All) and after that check you’re not using asynchronous calls inside onSubmit (which would allow the form to submit before the callback runs)........

 

If you found my response helpful, please mark it as ‘Accept as Solution’ and ‘Helpful’. This helps other community members find the right answer more easily and supports the community.

 

Thanks and Regards,
Kaushal Kumar Jha - ServiceNow Consultant - Lets connect on Linkedin: https://www.linkedin.com/in/kaushalkrjha/