Changing Field Style for Problem Tasks if due date is passed

Joe Taylor
Giga Guru

I'm trying to change the font color of the due dates in the list view of PTASKS if the due date is past, but no matter what I try it doesn't seem to work.

Here's what I have now:

Table: Problem Task [problem_task]

Field Name: Due date

Value: javascript:gs.dateDiff(current.due_date.getDisplayValue(),gs.nowDateTime(),true) <  0 ;

Style:  color:red;

What am I doing wrong?

Also, where can if find a comprehensive list of styles  (colors, background, font sizes, etc.) ?

 

 

1 ACCEPTED SOLUTION

If its exceeding the field limits then you can put the code in script include and from there return true/false.

Like for yellow you could do this.

1) Create a script include (I named mine as TestDate)
find_real_file.png

 

2) Then call the script include (and function - which I named isYellow) from Styles
find_real_file.png

 

Could you please mark my answer as correct? It gives me few points on community.

Thank you!

 

-Tanaji

Please mark reply correct/helpful if applicable

View solution in original post

21 REPLIES 21

Joe Taylor
Giga Guru

Here's what I'm trying, but I still see the red dot on all PTASK,even those that are closed.

javascript: var answer = (current.due_date.getDisplayValue() <= (new GlideDateTime().getDisplayValueInternal())) && current.sys_class_name == 'problem_task' && current.state != 'Closed Complete'; answer;

You are almost there.

Only thing you need to change is "Closed Complete". Its the label and you need to replace it with backend value of it which might be a numberical value (btw the state on problem_task has Closed [value - 157] OOTB). If you are using OOTB values then you could use

javascript: var answer = (current.due_date.getDisplayValue() <= (new GlideDateTime().getDisplayValueInternal())) && current.sys_class_name == 'problem_task' && current.state != '157'; answer;

 

 

Easiest way to get backend values is to get the filter you want on list view (of table required in this case task) and then right click on breadcrumbs >> Copy query. This will give you all the field names and backed values used in the filters. Use the same values in your code. 

 

-Tanaji

Please mark response correct/helpful if applicable

Joe Taylor
Giga Guru

That's awesome!  Thanks for the tip about looking at values in a list view.  That will really help in the future.

 

So here's what I have now that's working perfectly:

javascript: var answer = (current.due_date.getDisplayValue() <= (new GlideDateTime().getDisplayValueInternal())) && current.sys_class_name == 'problem_task' && current.state  < '3' ; answer;

 

I then went ahead and created another style for "green":

 

javascript: var answer = (current.due_date.getDisplayValue() > (new GlideDateTime().getDisplayValueInternal())) && current.sys_class_name == 'problem_task'; answer;

background-color: green

 

This works fine too.  So with both of these every PTASK has a green or red dot.

 

 

Now I'm trying to get a little fancier.

I want to only make those PTASKS green that are more than 7 days in the future.

So I did this, but it doesn't work.  No tasks show up with green dots.

javascript: var answer = (current.due_date.getDisplayValue() > 7 + (new    GlideDateTime().getDisplayValueInternal())) && current.sys_class_name == 'problem_task'; answer;

background-color: green

 

I'm guessing these Fields styles are evaluated sequentially and when all the conditions are met for one, it stops evaluating more.  Is this correct?

So here's my logic: 

Style1 (red) If due date is < current date

Style2 (green) If due date is > current date + 7 days

Style3 (yellow) If due date is > current date AND <= current date + 7 days

 

 

You cannot add integers to date objects directly. You need to use addDays().

Try this for green-

javascript: var gdt = new GlideDateTime(); gdt.addDays(7); var answer = (current.due_date.getDisplayValue() > gdt.getDisplayValueInternal()) && current.sys_class_name == 'problem_task'; answer;

background-color: green

 

Similarly for yellow try this-

javascript: var gdt = new GlideDateTime(); gdt.addDays(7); var answer = (current.due_date.getDisplayValue() > (new GlideDateTime().getDisplayValueInternal())) && (current.due_date.getDisplayValue() <= gdt.getDisplayValueInternal()) && current.sys_class_name == 'problem_task'; answer;

background-color: yellow

 

No, there is no order (and no order field) in evaluating these tyles. I believe it will simple pick up a random one if that happens. So make sure none of your condition is having collision with other.

I see that you have included current.state in the red style. Shouldn't it be in others as well? (Like current.state >= 3 or current.state < 3 or current.state == 3)

 

-Tanaji

Please mark response correct/helpful if applicable

Joe Taylor
Giga Guru

Thank you so much!

Everything is working exactly as I was hoping for now.

Red, Yellow and Green dots are showing up on Task View and problem view with corresponding due dates.

Here's what my 3 styles finally look like now:

 

Table: Task

Field Name:  Due Date

Value: javascript: var answer = (current.due_date.getDisplayValue() <= (new GlideDateTime().getDisplayValueInternal())) && current.sys_class_name == 'problem_task' && current.state  < '3' ; answer;

background-color: red

 

Table: Task

Field Name:  Due Date

Value: javascript: var answer = (current.due_date.getDisplayValue() > (new GlideDateTime().getDisplayValueInternal())) && current.sys_class_name == 'problem_task' && current.state  < '3' ; answer;

background-color: yellow

 

Table: Task

Field Name:  Due Date

javascript: var gdt = new GlideDateTime(); gdt.addDays(7); var answer = (current.due_date.getDisplayValue() > gdt.getDisplayValueInternal()) && current.sys_class_name == 'problem_task' && current.state < '3' ; answer;

background-color: green

 

Couldn't use your suggest value for "yellow" since it was too long to fit into the window.

But my three styles seem to be evaluated correctly anyway.

 

Thanks again