How do I add a style for a list view only?

DrewW
Mega Sage
Mega Sage

I found this today and I like the idea
http://wiki.service-now.com/index.php?title=Indicating_Updated_Tickets

But my issue is I only want it to display on the list. Does anyone know of a way to detect what the user is viewing so I can add to the condition?

12 REPLIES 12

DrewW
Mega Sage
Mega Sage

Just incase someone would like to know how to do this, this is how I did it.

Create 2 Global Business Rules with the following names and code.

function incidentGetViewName() {
gs.getSession().putProperty("isListView", "false");
}

function incident_listGetViewName() {
gs.getSession().putProperty("isListView", "true");
}

Then add the follow condition to your style when you would like it to apply to a list only.
gs.getSession().getProperty("isListView")=="true"


JoeLighthall
Giga Contributor

So I wanted to do this and could not get it to work they way this article suggests. Ultimately in the condition of the style i did this...

javascript: gs.action.getGlideURI().get('sysparm_view') == '' &&

The view name must be the correct case or this will fail. You can see the view name by either looking at the details of the module or personalizing the list layout in list view.

I hope this is helpful.

Joe


Markus Schaefer
ServiceNow Employee
ServiceNow Employee

Hi Drew,



can you please share some more details on this solution? It seems as we have a similar requirement at a customer and I didn't get it to work up to now. It would be great if you could give me some more information.



Best regards,


Markus


Not sure what else I can add.   You do not actually need two business rules, you can have all of the functions in one and have it run on the task table.   You can also put the style on the task table also.



This is the code in our BR.


function incident_listGetViewName() {
gs.getSession().putProperty("isListView", "true");
}


function incidentGetViewName() {
gs.getSession().putProperty("isListView", "false");
}



function u_incident_AttachmentGif() {
try{
  if (current.u_has_attachments && gs.getSession().getProperty("isListView") != "false") {
    return true;
  } else {
    return false;
  }
} catch(e){
  return true;
}
}



We then use a style on the task table and the number field with a value of "javascript:u_incident_AttachmentGif();" and a style of


background-image: url('./images/attachment.gif');


background-repeat: no-repeat;


background-position: 2 2;


text-indent: 16px;



Not sure what else I can add other than we have a "Has Attachments(u_has_attachments)" field that we set to true or false based on if the record has an attachment in the sys_attachment table.