Wanted to hide Attachment field for the default view in custom table.

Praju_123
Tera Contributor

I'm trying to hide the attachment field from the form only in the default view. It should remain visible in all other views.

To achieve this, I wrote the following onLoad client script, but the field is still not hiding. I'm sharing the code below for your reference:

Praju_123_0-1754917177985.png

 

function onLoad() {
    var viewName = g_form.getViewName();

    if (viewName === 'default') {
        // Disable the paperclip icon for adding new attachments
        g_form.disableAttachments();

        // Hide the attachment section (classic UI)
        var attachSection = document.getElementById('header_attachment');
        if (attachSection) {
            attachSection.style.display = 'none';
        }

        // Hide the attachment separator line if present
        var attachLine = document.getElementById('header_attachment_line');
        if (attachLine) {
            attachLine.style.display = 'none';
        }
    }
}

Despite this, the attachment field is still visible. Could you please help us identify what might be missing or suggest an alternative approach?
2 ACCEPTED SOLUTIONS

@Praju_123 , I submitted a record producer on the Incident table and attached a file during submission. However, when I returned to the form view of the table, the attachment clip was not visible for default view. Client script was working fine.

If this works, please mark it as helpful/accepted — it keeps me motivated and helps others find solutions.
Shashank Jain – Software Engineer | Turning issues into insights

View solution in original post

@Praju_123 

what do you mean by attachment field?

you are trying to remove the top header attachment icon and the header row right?

how is file attached to record producer?

Via paper-clip icon or some attachment variable?

share screenshots

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

View solution in original post

14 REPLIES 14

@Ankur Bawiskar 
still, it's not working.

@Ankur Bawiskar 
It works only when the attachment field is empty.
However, in our use case, the record is created via a Record Producer, and an attachment is uploaded during that process.
We want the attachment field to be hidden in the default view, but visible in the Workspace view.

@Praju_123 

Sorry but you didn't mention what came in alert?

what came in alert?

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 , 

"default" coming in alert , @Praju_123 mentioned in below replies.

If this works, please mark it as helpful/accepted — it keeps me motivated and helps others find solutions.
Shashank Jain – Software Engineer | Turning issues into insights

I was working on this question — by the way, great solution, @Ankur Bawiskar !

I  learned about Isolate Script.

One more thing I discovered while solving this question is that we cannot define "default" in the View Name field of a client script. 

It should be working @Praju_123  , I tried it on PDI and the solution @Ankur Bawiskar provided is working.
cc:  @Nikhil Bajaj9 

If this works, please mark it as helpful/accepted — it keeps me motivated and helps others find solutions.
Shashank Jain – Software Engineer | Turning issues into insights