- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-15-2020 08:24 AM
script working in portal view ......
but console view if i attach one attachment it is allowing to submit ticket ,but requirement is 2 attachment mandatory
so that is not working in console view...
function onSubmit() {
//Type appropriate comment here, and begin script belo
if (g_form.getValue('request') == 'Job')
{
try {
var msg = 'Please attached the job template(s) required and the COE approval email ';
var attachments = document.getElementById('header_attachment_list_label');
// g_form.addInfoMessage("Attachment visibility: " + attachments.style.visibility + " attachment display: " + attachments.style.display);
if (attachments.style.visibility == 'hidden' || attachments.style.display == 'none') {
alert(msg);
return false;
}
}
// For Service Portal
catch (e) {
var count = getSCAttachmentCount();
if (count <=1)
{
alert(msg);
return false;
}
}
}
}
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-16-2020 12:51 AM
Hi Sai,
please refer below blog and it would help you solve that;
Verify Mandatory Attachments Count on Catalog Item
Mark ✅ Correct if this solves your issue and also mark 👍 Helpful if you find my response worthy based on the impact.
Thanks
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-15-2020 08:37 AM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-15-2020 08:42 AM
If required replace you try block with below.
try {
var msg = 'Please attached the job template(s) required and the COE approval email ';
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("More than 2 attachmens are required.");
return false;
}
else
{
return true;
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-15-2020 09:28 AM
Hi Jaspal,
Thank you so much for your rply
i wrote this code still its not came ...if i attach any attachments always show More than 2 attachments are required
function onSubmit() {
//Type appropriate comment here, and begin script belo
if (g_form.getValue('request') == 'Job'){
var msg = 'Please attached the job template(s) required and the COE approval email ';
var proof = g_form.getUniqueValue();
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("More than 2 attachmens are required.");
return false;
}
else
{
return true;
}
}
}
if i dint attach anything just clicked submit button it is showing this More than 2 attachmens are required.
and it wont work gel below so i used var proof = g_form.getUniqueValue();
and i want it should work both console and portal view.
gel('sysparm_item_guid').value;

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-15-2020 09:43 AM
Is this for HR Cases or RITM?
For RITM: attachment.addQuery("table_name", "sc_cart_item");
For HR Cse: attachment.addQuery("table_name", "COE_Table_Name_here");