A different approach to attachments

General Add comments
by:

One of our customers had the need to hide attachments under certain curcumstances on tickets. Now, with out of the box ServiceNow, the user can see all attachments if he has read access to the ticket. An additional demand was that they wanted to give their attachments a name (within ServiceNow).

Out of the box, it is not possible to name your attachments, and it’s not possible to customize the ‘Attachments’ functionality. So, we had to come up with some way to allow this.
image002

Our solution to this problem was to add the related list for the attachments to the specific table. This will also allow you to use list control options for creating new attachments. After adding the related list, you can add a ‘name’ field to the dictionary. Don’t forget to add it to the list layout. Now, remember to check the list edit rights on your instance, otherwise it will not be possible to edit the name of your attachments.

image004
As for hiding the attachments list, we need to put the following line of code in a client script. You can add your custom conditions to this line of code.

g_form.hideRelatedList('u_relatedlist');

Now, this is not enough for hiding the attachments. The thing is, you are hiding the related list, but at the top of the ticket, the attachments are still displayed.
image006
In order to hide this, an onLoad clientscript is necessary. The following script will hide the attachments bar for you:

function onLoad() {
if (gel('header_attachment') != null)
gel('header_attachment').hide();
if (gel('header_attachment_line') != null)
gel('header_attachment_line').hide();
if (gel('header_add_attachment') != null)
gel('header_add_attachment').hide();
}

If you have any questions, please don’t hesitate to drop me an e-mail on .img[at].img

Leave a Reply