Onsubmit Client Script to check Attachments on Record producer
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-04-2018 05:33 AM
Hello,
I have a record producer on a custom table in custom application which has check box if checked need to attach the files , so i have been using below code it is working but even after attaching on the form i am getting same Alert and unable to submit the form , any help in this is much appreciated!
Onsubmit Client script code :
function onSubmit() {
attachOne = g_form.getValue('one');
attachTwo = g_form.getValue('two');
attachThree = g_form.getValue('three');
if(attachOne == 'true' || attachTwo == 'true' || attachThree == 'true') //checking if any of the attachment checkbox is ticked
{
var att = new GlideRecord("sys_attachment");
att.addQuery("table_name", "sc_cat_item_producer");
att.addQuery("sys_created_by", g_user.userName);
att.query();
if(!att.next())
{
alert("Please attach the Required Documnet to proceed with submitting.");
return false;
}
}
}
- Labels:
-
Service Catalog

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-04-2018 05:43 AM
PLease refer the below thread
https://community.servicenow.com/community?id=community_question&sys_id=ec764fe1db1cdbc01dcaf3231f9619e2
Change your code as below
- var sys_id = gel('sysparm_item_guid').value;
- var attachment = new GlideRecord('sys_attachment');
- attachment.addQuery('table_name','table name'); //my custom table is "table name"
- attachment.addQuery('table_sys_id',sys_id);
- attachment.query();
- if (!attachment.next()) {
- alert ("PLEASE ATTACH Attachment");
- return false;
- }
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-04-2018 05:56 AM
Quick question :
About this line
attachment.addQuery('table_name','table name'); //my custom table is "table name"
So the table name gonna be where my Record producer sits which is "sc_cat_item_producer"
or the Custom table on which the record producer creates the record ?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-04-2018 06:03 AM
In table name, you have to pass the table name where your record is going to create and not sc_cat_item_producer
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-04-2018 06:44 AM
Thanks for your response!
I have gotta workout this on Service Portal so it is not working with above script. any thoughts ?