- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-29-2015 01:50 AM
I'd like to avoid submitting without any attachment using record producer. And I wrote a catalog client script as below.
But at the point of time, we can't get the sys_id of the submitting record. And it seems that sys_attachment table doesn't have the record yet. So the client script always alerts.
Is there any way to show an error message when submitting with no attachment? The page where users input values needs to stay.
Thanks.
function onSubmit() {
// alert(g_form.getUniqueValue());
var att = new GlideRecord('sys_attachment');
att.addQuery('table_sys_id', g_form.getUniqueValue());
att.query();
if(!att.next()) {
alert("No attachment");
return false;
}
return true;
}
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-29-2015 05:59 AM
You have to create a catalog client script .
function onSubmit() {
var cat_id = gel('sysparm_item_guid').value;
var gr = new GlideRecord("sys_attachment");
gr.addQuery("table_name", "sc_cart_item");
gr.addQuery("table_sys_id", cat_id);
gr.query();
if (!gr.next()) {
alert("You must attach a file to submit.");
return false;
}
}
its not a best practice....but a work around ...best practice is you have to create a script include and call a glide ajax
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-29-2015 01:57 AM
Hi Koji,
Event is fired when you upload the file to the record so you can check the event if it is equal to the below.
attachment.uploaded: An attachment has been uploaded. If multiple attachments are uploaded to a record at one time, only one event will be created.
Then you can popup the window for information if attachment is there or not.
Find further information below.
Administering Attachments - ServiceNow Wiki http://wiki.servicenow.com/index.php?title=Administering_Attachments
Regards,
Atul Kumar
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-29-2015 05:59 AM
You have to create a catalog client script .
function onSubmit() {
var cat_id = gel('sysparm_item_guid').value;
var gr = new GlideRecord("sys_attachment");
gr.addQuery("table_name", "sc_cart_item");
gr.addQuery("table_sys_id", cat_id);
gr.query();
if (!gr.next()) {
alert("You must attach a file to submit.");
return false;
}
}
its not a best practice....but a work around ...best practice is you have to create a script include and call a glide ajax
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-29-2015 06:01 AM
And if you find this correct solution please mark it helpful and correct as well
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-29-2015 05:13 PM
Hi Ankit,
Thank you for your reply. Actually table_name is another and not needed. But it works!
Could you tell me why it's not best practice? I tryed to create a script include but it didn't return value well.
Thanks,
Koji