Need help on business rule

Nivedita9
Tera Contributor

Hi,
I had a requirement to restrict attachment upto 25 mb on few tables. This functionality works fine it does restrict user from uploading file more than 25 MB but it temporary add empty file (adding as screenshot) which disappears when I reload the form.
Business Rule:

  try {
        var checkAttachmentSize;
        var attachmentFlag = false;
        // List of tables to check
        var allowedTables = ['task', 'cmdb_ci'];
        var attachemtTable = current.table_name;
        // Get the base table for the given table name
        var baseTable = String(new global.Hnk_project_process().getBaseTable(attachemtTable));
        var grRecord = new global.Hnk_project_process().getScope(attachemtTable);
        var kbRecord = new global.Hnk_project_process().getKnowledgeBase(current.table_sys_id);
        // If the base table matches and the attachment exceeds max size, restrict it
        // gs.log("Knowledge Base--" + kbRecord + 'and' + attachemtTable, '144');
        if ((allowedTables.includes(baseTable) && !grRecord.startsWith('Human')) || (attachemtTable == 'kb_knowledge' && !kbRecord.startsWith('HR'))) {
            checkAttachmentSize = new global.Hnk_project_process().getAttachmentSize(current);
            var totalSize = parseInt(current.size_bytes) + checkAttachmentSize;
            var maxSize = 25 * 1024 * 1024;
            if (totalSize > maxSize) {
                attachmentFlag = true;
                gs.addErrorMessage('Total attachments on this record cannot exceed 25 MB.');
                current.setAbortAction(true);
            }
        }
    } catch (ex) {
        gs.error("Attachment could not be find." + ex.message);
    }

Nivedita9_0-1747129883191.png

 

8 REPLIES 8

@Nivedita9 

Is this happening on the tables where this validation is present?

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

yes. I tried on incident and attached the screenshot. If I upload less than 25 MB it works fine but If I upload more than 25 MB I see this behavior

@Nivedita9 

I am able to replicate this issue in Yokohama, I didn't verify it in other instance

Please raise a case with ServiceNow for the same.

AnkurBawiskar_0-1747132493231.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

But our instance is on Xanadu--xanadu-07-02-2024__patch8-03-26-2025