- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-20-2018 03:41 PM
I have a requirement where i need to check if the catalog item have 2 attachments , if not it should not submit ,
i am able to check the attachment by using on submit client script on the catalog item but how and where to include the count ?
Can some one help me with that
function onSubmit() {
//Type appropriate comment here, and begin script below
var proof = gel('sysparm_item_guid').value;
var att = new GlideRecord("sys_attachment");
att.addQuery("table_name", "sc_cart_item");
att.addQuery("table_sys_id", proof );
att.query(att);
if (!att.next()) {
alert("Please include the attachments");
return false;
}
return true;
}
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-21-2018 06:18 AM
You can try with this code:
var proof = gel('sysparm_item_guid').value;
var rowcount=0;
var attachment = new GlideRecord("sys_attachment");
attachment.addQuery("table_name", "sc_cart_item");
attachment.addQuery("table_sys_id", proof);
attachment.query();
while (attachment.next()) {
rowcount++;
}
//alert("Row "+rowcount);
if(rowcount <= 2)
{
alert("message");
return false;
}
else
{
return true; }
}
https://community.servicenow.com/community?id=community_question&sys_id=cd49c325db5cdbc01dcaf3231f961992
Thanks
Shashikant
Hit Helpful or Correct on the impact of response.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-20-2018 04:09 PM
try below, ref - http://www.servicenowelite.com/blog/2017/5/12/service-portal-require-attachments
function onSubmit() {
var count = getSCAttachmentCount();
if(count <= 2) {
alert('Please include the attachments');
return false;
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-21-2018 06:10 AM
even though i add 2 attachments its showing the alert

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-21-2018 06:14 AM
than change below
count < 2

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-21-2018 06:17 AM
or
if(count > 2) {
alert('Please include the attachments');
return true;
}else{
alert('Please include the attachments');
return false;
}