- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-25-2023 07:25 AM
Hello,
I am currently working on a client script that will validate an attached signature to a ticket before allowing the user to close the ticket. I have the following GlideAjax call in my script to search for the attachment.
var ga = new GlideAjax('CheckAttachment');
ga.addParam('sysparm_name', 'getSignature');
ga.addParam('table_name', 'x_nuvo_eam_facilities_work_orders');
ga.addParam('table_sys_id', g_form.getUniqueValue());
ga.addParam('file_name' ,'signature.png');
Is there a way with GlideAjax to make the Param in line 5 to simply search the file_name field for any file who's name contains "signature"? I know with a GlideRecord I could use "CONTAINS", but that doesn't seem to work here.
Thanks,
Andrew
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-25-2023 07:47 AM - edited 04-25-2023 07:48 AM
Hi, I think you can do it like in the following
// In your call Ajax
var ga = new GlideAjax('CheckAttachment');
ga.addParam('sysparm_name', 'getSignature');
ga.addParam('table_name', 'x_nuvo_eam_facilities_work_orders');
ga.addParam('table_sys_id', g_form.getUniqueValue());
ga.addParam('file_name' ,'signature'); // Search any keyword
// THE SCRIPT INCLUDE
// Get parameters
var table_name = this.getParameter('table_name');
var table_sys_id = this.getParameter('table_sys_id');
var keyword = this.getParameter('file_name');
// Fetch the attachment
var gr = new GlideRecord('sys_attachment');
gr.addQuery('table_sys_id', table_sys_id);
gr.addQuery('table_name', table_name);
gr.addQuery('file_name', 'CONTAINS',keyword ); // Search any keyword
gr.setLimit(1);
gr.query();
if (gr.next()){ return (gr.file_name.toString());}
return false;
Regards
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-25-2023 07:52 AM
You can modify your server-side script to search for file names containing "signature" instead of trying to achieve this directly in the GlideAjax call. Here's how you can do that:
- Update your 'CheckAttachment' Script Include:
In the 'getSignature' function, modify the query to use "CONTAINS" for the file name. Here's an example:
javascriptCopy code getSignature: function() { var tableName = this.getParameter('table_name'); var tableSysId = this.getParameter('table_sys_id'); var fileName = this.getParameter('file_name'); var attachment = new GlideRecord('sys_attachment'); attachment.addQuery('table_name', tableName); attachment.addQuery('table_sys_id', tableSysId); attachment.addQuery('file_name', 'CONTAINS', fileName); attachment.query(); // Add your logic
- Your existing GlideAjax call should now work as expected:
javascriptCopy code var ga = new GlideAjax('CheckAttachment'); ga.addParam('sysparm_name', 'getSignature'); ga.addParam('table_name', 'x_nuvo_eam_facilities_work_orders'); ga.addParam('table_sys_id', g_form.getUniqueValue()); ga.addParam('file_name', 'signature');
Now, the server-side function 'getSignature' will search for any attachment with a file name containing "signature" in the specified table and record.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-25-2023 07:47 AM - edited 04-25-2023 07:48 AM
Hi, I think you can do it like in the following
// In your call Ajax
var ga = new GlideAjax('CheckAttachment');
ga.addParam('sysparm_name', 'getSignature');
ga.addParam('table_name', 'x_nuvo_eam_facilities_work_orders');
ga.addParam('table_sys_id', g_form.getUniqueValue());
ga.addParam('file_name' ,'signature'); // Search any keyword
// THE SCRIPT INCLUDE
// Get parameters
var table_name = this.getParameter('table_name');
var table_sys_id = this.getParameter('table_sys_id');
var keyword = this.getParameter('file_name');
// Fetch the attachment
var gr = new GlideRecord('sys_attachment');
gr.addQuery('table_sys_id', table_sys_id);
gr.addQuery('table_name', table_name);
gr.addQuery('file_name', 'CONTAINS',keyword ); // Search any keyword
gr.setLimit(1);
gr.query();
if (gr.next()){ return (gr.file_name.toString());}
return false;
Regards
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-25-2023 07:52 AM
You can modify your server-side script to search for file names containing "signature" instead of trying to achieve this directly in the GlideAjax call. Here's how you can do that:
- Update your 'CheckAttachment' Script Include:
In the 'getSignature' function, modify the query to use "CONTAINS" for the file name. Here's an example:
javascriptCopy code getSignature: function() { var tableName = this.getParameter('table_name'); var tableSysId = this.getParameter('table_sys_id'); var fileName = this.getParameter('file_name'); var attachment = new GlideRecord('sys_attachment'); attachment.addQuery('table_name', tableName); attachment.addQuery('table_sys_id', tableSysId); attachment.addQuery('file_name', 'CONTAINS', fileName); attachment.query(); // Add your logic
- Your existing GlideAjax call should now work as expected:
javascriptCopy code var ga = new GlideAjax('CheckAttachment'); ga.addParam('sysparm_name', 'getSignature'); ga.addParam('table_name', 'x_nuvo_eam_facilities_work_orders'); ga.addParam('table_sys_id', g_form.getUniqueValue()); ga.addParam('file_name', 'signature');
Now, the server-side function 'getSignature' will search for any attachment with a file name containing "signature" in the specified table and record.