Need help on UI Page

AbhitK
Tera Contributor

Hi All,
I need some help here.
Use Case- Restrict attachment insertion for more than 25 MB on knowledge table but this restriction should not be applied for view HR(custom view). Also the warning which is added on attachment UI Page should not be visible to knowledge record where view is HR.
The solution which I have right now works well post submission of record but doesn't work on new record.
Here are the snapshot:
Business Rule (On attachment table, before business rule)

AbhitK_0-1753269866888.png


2. UI Page:

AbhitK_2-1753269984479.png

On UI page I'm trying get the view of new knowledge record, but it is giving me log in null.
Any help on this would be a great help.

 



5 REPLIES 5

Ankur Bawiskar
Tera Patron
Tera Patron

@AbhitK 

There is some issue going on in community that images are not visible.

please add it using browse feature and add as attachment to post

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

Business Rule:(On Attachment table,before 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
            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);
        }
    

@AbhitK 

if you are planning to customize the OOTB attachment UI page, I will recommend not to do that.

I will push back on this requirement as you are touching an OOTB component.

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

@Ankur Bawiskar  it's already customized and this is how we are restricting heading 
 <j2:if test="$[!scope.contains('sn_hr')]"> 
    <j2:if test="$[!scope]">
   
        <!--<j2:if test="$[jvar_sysparm_view.indexOf('askhr') != 0]">-->
        <h3 style="text-align: center; font-size: 15px; font-weight: bold;">Restrict the file upload of size more than 25MB.</h3>
    </j2:if>
    <input type="hidden" id="ni.show_rename_link" name="ni.show_rename_link" value="${jvar_can_add_attachments}" />