Glideajax method is not working
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
HI Community,
I have a requirement, in a catalog item we have variables like name, type, target and table. when user fill the details and while submit the form , in sla definition table if we have records with same name, type , table and target then it should not submit the form it should throw an error.
for this i have tried client script and script include but form is getting submitted any how not sure what is wrong in it.
client script;
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago - last edited 3 weeks ago
HI @Deepak Shaerma ,
Thanks for finding the spelling error do i need to write this inside the variable set or in catalog item the client script one?
Im trying but im getting this annotation
New client-scripts are run in strict mode, with direct DOM access disabled. Access to jQuery, prototype and the window object are likewise disabled. To disable this on a per-script basis, configure this form and add the "Isolate script" field. To disable this feature for all new globally-scoped client-side scripts set the system property "glide.script.block.client.globals" to false.
Not sure what it means not faced it before and it says This catalog client script is not VA supported due to the presence of the following variables in the script: g_form.submitted
One more thing i observe is that it seems script include is not running or not sure i have added the log there but i don't see them in log table
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
Hi @suuriyas ,
I saw two issues in above given code, 1. syntax error - replace - sysparm_name, 2. GlideAjax is async so it will not wait for the response and it will submit the form. Instead you can try to use OnChange Client script.
Please mark my answer correct and helpful if this works for you
Thanks and Regards,
Sarthak
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago - last edited 3 weeks ago
Thanks for replying
Client script i tried but did not work
One more thing i observe is that it seems script include is not running or not sure i have added the log there but i don't see them in log table
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
Hi @suuriyas ,
Please try to add logs/alert and check which line causing issue
SI - Must be glideAjax/Client callable
checkDuplicate: function() {
var name = this.getParameter('sysparm_name_val');
var type = this.getParameter('sysparm_type_val');
var target = this.getParameter('sysparm_target_val');
var table = this.getParameter('sysparm_table_val');
var gr = new GlideRecord('contract_sla');
gr.addQuery('name', name);
gr.addQuery('type', type);
gr.addQuery('target', target);
gr.addQuery('collection', table);
gr.query();
if(gr.next()){
gs.log("Inside IF Condition") // User gs.info if working in scope app
return "true";
}else{
return "false";
}
return gr.next() ? "true" : "false";
}
Client Script - OnChange
var name = g_form.getValue('name');
var type = g_form.getValue('type');
var target = g_form.getValue('target');
var table = g_form.getValue('collection');
alert("Name = " + name + " Type = " + type + " Target = " + target + " Table = " + table )
if(!name || !type || !target || !table){
return;
}
var ga = new GlideAjax('SLAValidationUtils');
ga.addParam('sysparm_name','checkDuplicate');
ga.addParam('sysparm_name_val',name);
ga.addParam('sysparm_type_val',type);
ga.addParam('sysparm_target_val',target);
ga.addParam('sysparm_table_val',table);
ga.getXML(function(response){
var answer = response.responseXML.documentElement.getAttribute("answer");
alert("Answer = " + answer);
if (answer == "true") {
alert(" Inside if Answer True = " + answer);
g_form.addErrorMessage("SLA with same name, type, target and table already exists");
return;
}
}
Please mark my answer correct and helpful if this works for you
Thanks and Regards,
Sarthak
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
HI @Sarthak Kashyap ,
I have done some modification in the script and im almost there
Client script: