Requirement to abort catalog request submission if requested for is female
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-28-2024 12:53 AM
Hello everyone,
this is the code I have written but I am unable to abort catalog form submission. What might be the issue?
//SCRIPT INCLUDE var abortfemalerequester = Class.create(); abortfemalerequester.prototype = Object.extendsObject(AbstractAjaxProcessor, { getreqGender: function() { var gr = new GlideRecord('sys_user'); var reqId = this.getParameter('sysparm_id'); gr.addQuery('sys_id', reqId); gr.query(); if (gr.next()){ gr.log('Gender is: ' + gr.gender); var gender = gr.gender; var ans; if (gender == 'Male'){ gs.log('You are inside male condition'); return (true); }else if (gender == "Female"){ gs.log('You are inside female condition'); return (false); } } }, type: 'abortfemalerequester' });
function onSubmit() { //Type appropriate comment here, and begin script below var ga = new GlideAjax('abortfemalerequester'); ga.addParam('sysparm_name', 'getreqGender'); ga.addParam('sysparm_id', g_form.getValue('requested_for')); ga.getXML(getResponse); return false; function getResponse(response){ var answer = response.responseXML.documentElement.getAttribute('answer'); alert (answer); if (answer == "true"){ g_form.submit(); } } }
Thanks in advance 🙂
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-28-2024 12:59 AM
Hi @Snow-Man ,
Assuming the script is working fine,
You have written GlideAjax on submission of form , it will not wait for the system to return the values.
You can refer to below KB :
https://support.servicenow.com/kb?id=kb_article_view&sysparm_article=KB0783579
You can refer to below article as well :
Please mark helpful/correct if my response helped you.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-28-2024 01:12 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-28-2024 09:43 AM
Hi @Southsayer
What changes you want me to do in the script ?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-28-2024 01:16 AM
Hi @Snow-Man do the below changes in your script include
return (true); change to return "true"
return (false);change to return "false"
because in client script your checking
if (answer == "true") // this will not match (true)
Harish