Requirement to abort catalog request submission if requested for is female

Snow-Man
Tera Contributor

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 🙂

4 REPLIES 4

Anubhav24
Mega Sage
Mega Sage

 

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 :

https://www.servicenow.com/community/developer-articles/async-validation-in-onsubmit-catalog-client-...

 

Please mark helpful/correct if my response helped you.

 

Hello @Anubhav24 

Could you please make the necessary changes in the script? 

 

Hi @Southsayer 

What changes you want me to do in the script ?

Harish KM
Kilo Patron
Kilo Patron

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)

Regards
Harish