Conditionally preventing images from showing up in the activity log

Anthony10
Giga Contributor

I'm currently trying to prevent image attachments from appearing as thumbnails in the activity log.

The thumbnails should be visible when the image is attached, but after a certain field on the form is toggled, a user should no longer be able to see the thumbnails in the activity log. The user should still be able to view the attachments from the attachment related list or the list located in the header, I'm just trying to prevent that thumbnail from appearing.

I thought that all of the records in the activity log were stored in the sys_history_line table, but it seems that attachments don't show up there?

1 ACCEPTED SOLUTION

Anthony10
Giga Contributor

I found a solution. Originally I wanted to do this in a UI Macro/Formatter, but it kept breaking our form page.

I created an onLoad client script that finds the HTML elements on the page that display the thumbnail images. I then hide those elements, if certain conditions are met, and add a line of text in their place that notifies the user that the thumbnail was hidden.

It seems to work well enough.

View solution in original post

6 REPLIES 6

Hi Vinoth, here is what I ended up doing in my onLoad client script:

var class_str = 'sn-card-component sn-card-component_attachment state-selectable'; 
var elems = document.getElementsByClassName(class_str);
var i;

for (i = 0; i < elems.length; i++) {
    var node = document.createElement("DIV");
	var text = document.createTextNode("** This image has been hidden **");
	node.appendChild(text);

	var parent = elems[i].parentElement;
	elems[i].style.display = "none";
	parent.appendChild(node);
}

It's not particularly pretty, but basically all I'm doing is looking up the HTML element that contains the attachment link, disabling all of it's children, and adding my own text element as a new child.

In order to enable DOM manipulation like this for client scripts, you must set the "Isolate Script" field on the client script form to false. By default this field is not visible on the form view so you'll have to add it.

It's worth pointing out that you can completely break the form view if you're not careful, so you should only use DOM manipulation as a last resort.

 

FernandoUrrutia
Tera Contributor

Hi, select "Attachments" on field "filter actity" and resolved.

Más de 5 años de experiencia implementando y gestionando ServiceNow.
Consultor certificado y especializado en la consultoría del producto.