- 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
‎02-21-2019 07:46 AM
Hi,
I have used to same code you provided. but no luck. There is no action being taken when I am trying submit the form.
I am using it for particular catalog item. any thoughts ?
thanks,
VC

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-28-2019 03:31 AM
Anyone who's wondering why this code is not working in current time though following all the suggestions, then let me tell you that there is a new option brought by SN from London release called Isolate script. This option is brought by SN to discourage the use of DOM in SN scripting.
For all existing configurations before London (both OOB & custom), Service Now has set the Isolate script to False so it won't impact any of your existing scripts. For all new configurations that were introduced as part of London(or future releases), the Isolate script is set to True.