How to count the attachments in catalog client script?

Buddy 1
Tera Contributor

Hi,

we have a custom variable called "sp_attachments" (which is drag and drop attachment).

On submission of case, if the "sp_attachments" variable is not having any attachment attached , then we should throw an error , "please attach something".

How to measure/condition for number of attachments attached in portal form ?How to achieve this in catalog client script?

 

Thanks in advance!

1 REPLY 1

Karthiga S
Kilo Sage

Hey @Buddy 1 

Here's the Catalog client script.

function onSubmit() {
var attachment = new GlideRecord('sys_attachment');
attachment.addQuery('table_sys_id', g_form.getUniqueValue());
attachment.addQuery('table_name', 'sc_cart_item');
attachment.query();
if (!attachment.next()) {
g_form.addErrorMessage('Please attach something');
return false;
}
return true;
}


This script checks if there are any attachments related to the current record in the 'sys_attachment' table. If there are no attachments, it adds an error message and prevents the form from being submitted.

 

Please note that this script will only work if the form is submitted after the attachments are added. If the attachments are added after the form is submitted, the script will not be able to detect them.

 

Also, please replace 'sc_cart_item' with the actual table name where your attachments are stored.

 

Please mark it Correct and Hit Like if you find this helpful!

 

Regards,

Karthiga