when user attaches an attachment of size more than 10 mb, it should show an alert message

CT00782576
Tera Contributor

Hi Experts, 
I have requirement as below
When user attaches an attachment of size more than 10 mb, it should show an alert message as Attachment size is exceeded, it should be on RITM  or catalog task table.

I want to implement this through client script.

 

Thanks,
Likhitha

7 REPLIES 7

@CT00782576 

Thank you for marking my response as helpful.

That's not possible using onChange catalog client script as in sys_attachment the sysId which gets linked with table_sys_id is dynamic

Why not use Attachment type variable and give max size attribute and create this variable for each of your items?

Something like this

AnkurBawiskar_0-1744363274895.png

 

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

@CT00782576 

Hope you are doing good.

Did my reply answer your question?

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

AnveshV38487537
Tera Contributor

Hi @CT00782576 

You can use below approach to show the alert message.

1.Create Before Business Rule on Attachment Table(sys_attachment) and add below condition.

When to run : Before
Filter condition : Table name   is    sc_req_item


2. In Advance tab, Glide the RITM table .

 

(function executeRule(current, previous /*null when async*/ ) {

    if(current.table_name == 'sc_req_item'){
    var req = new GlideRecord('sc_req_item');
    //req.addEncodedQuery('numberISNOTEMPTY^sys_id=' + current.table_sys_id);
    req.addQuery('sys_id', current.table_sys_id);
    req.query();
    while (req.next()) {
        if(current.size_bytes > 10485760)  // 10 MB = 10485760 bytes
        {
            gs.addErrorMessage('File size should not be more than 10 MB');
            current.setAbortAction(true);
            current.applyTemplate(false);

        }

    }
    }


})(current, previous);


So, once you added above condition and script, it will show the pop-up whenever you are adding attachment with file size more than 10 MB.

If my response helped please mark it correct and helpful . Happy Learning!

Regards
Anvesh