Glide Ajax not working on Submit Client script

Sowmya
Tera Contributor

Hello Community,

I have a written an onsubmit client in  Incident form using Script include but return false function is not working it is allowing me to resolve the incident which should not happen, Could anyone suggest as soon as possible.

 

Client script

function onSubmit() {


var assignmentgroup = g_form.getValue('assignment_group');
alert(assignmentgroup);
var ga = new GlideAjax('TagKB');//Scirpt Include name
ga.addParam('sysparm_name', 'getGroupDetails');//script Include Method
ga.addParam('sysparm_group', assignmentgroup);//parameter
ga.getXML(getResponse);
function getResponse(response) {

var answer = response.responseXML.documentElement.getAttribute("answer");
alert(answer);



/* var checkGroup = new GlideRecord('sys_user_group');
checkGroup.addQuery("sys_id",assignmentgroup);
checkGroup.query();
if(checkGroup.next()){

var validateKB=checkGroup.u_create_knowledge;
alert(validateKB);
}*/
//
var createknowledge = g_form.getValue('knowledge');
var resolutionKI = g_form.getValue('u_resolution_ki');
var state = g_form.getValue('incident_state');
var priority = g_form.getValue('priority');
if (state == '6') {
if ((((createknowledge == 'false') && (resolutionKI == '')) && (state == '6')) && ((priority == '1') || (priority == '2'))&&(answer=="true")){

alert('If a Knowledge Article exists for this solution, please select the Resolution KI under the Related Records tab. If no Knowledge Article exists, click the Create Knowledge Article checkbox.');
return false;
}

else if ((createknowledge == 'true') && (resolutionKI != '')) {
alert('Select either one of the options - If a Knowledge Article exists for this solution, please select the Resolution KI under the Related Records tab. If no Knowledge Article exists, click the Create Knowledge Article checkbox.');
g_form.clearValue(createknowledge);
return false;
}


}
}
}

Script Include: Script Include is working as expected (Basically i have created one custom field in group table if it is true then i am fetching the data)

var TagKB = Class.create();
TagKB.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getGroupDetails: function() {
var Group = this.getParameter('sysparm_group');
gs.log(Group);

var KBGroup = new GlideRecord('sys_user_group');
KBGroup.addQuery('sys_id', Group);
KBGroup.query();
if (KBGroup.next()) {
if (KBGroup.u_create_knowledge == true) {

return true;
} else {
return false;
}
}

},


type: 'TagKB'
});

1 REPLY 1

Sandeep Rajput
Tera Patron
Tera Patron

@Sowmya Since call to a script include from a client script is an asynchronous call (does not block the UI thread). Hence the moment you press submit button the form gets submitted without waiting for a response from the Server side. 

 

There are two ways to solve this issue.

1. Use getXMLWait(): Only works on the platform view and doesn't work on the Service Portal

2. Use the solution proposed here https://www.servicenow.com/community/developer-blog/how-to-async-glideajax-in-an-onsubmit-script/ba-.... which works on Platform view as well as the Service Portal.

 

Hope this helps.