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
Hi @suuriyas ,
Try add change your client script line with below line
Your line -
var table = g_form.getDisplayValue('collection');
Change with -
var table = g_form.getValue('collection');
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 ,
Yeah i tried that first if i add that
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
Hi @suuriyas ,
Maybe you can send the sys_id of your table/collection and get it in your script include and in your script include you can add one glideRecord on sys_db_object table to fetch table name and add that table name in your Glide record.
For example
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
Hi @suuriyas ,
i have updated few link in the script can you please check below
Client script -
function onSubmit() {
var mrvsData = g_form.getValue('sla_configuration');
if (!mrvsData) return true;
var rows = JSON.parse(mrvsData);
if (!rows || rows.length === 0) return true;
var name = rows[0].name;
var type = rows[0].type;
var target = rows[0].target;
var table = rows[0].collection;
var ga = new GlideAjax('SLAValidationUtils');
ga.addParam('sysparam_name', 'checkDuplicate');
ga.addParam('sysparam_name_val', name);
ga.addParam('sysparam_type_val', type);
ga.addParam('sysparam_target_val', target);
ga.addParam('sysparam_table_val', table);
var response = ga.getXMLWait(); // synchronous call
var answer = response.documentElement.getAttribute("answer");
if (answer == 'true') {
g_form.addErrorMessage("SLA with same name, type, target and table already exists");
return false; // stop submission
}
return true; // allow submission
}
Script include -
var SLAValidationUtils = Class.create();
SLAValidationUtils.prototype = Object.extendsObject(AbstractAjaxProcessor, {
checkDuplicate: function() {
var name = this.getParameter('sysparam_name_val');
var type = this.getParameter('sysparam_type_val');
var target = this.getParameter('sysparam_target_val');
var table = this.getParameter('sysparam_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();
return gr.next() ? 'true' : 'false';
}
});NOTE -
- Use getXMLWait() for synchronous validation in onSubmit.
- Do not call g_form.submit() manually inside the callback.
- Always return false when validation fails.
Thanks,
Rithika.ch