Hello,
Having issues trying to get this to work. I am in dashboard using list widget, advanced formatting. The goal is if
#1. postdate > 48 hours, background changes to red.
#2. but if postdate is empty or if there is a close date, do nothing
#3. also if there is no postdate or no close date, do nothing.
I can get a part of it to work but not all of it. I have tried using IIF and WHEN.
What I have tried and the results. All help is appreciated. Thank you.
var pastduecolor = IIF(IsEmpty($datapoint.campclosedate) && (currentdate > twodayslater), " ", "#BE2528")
When using the above #1, #3 work
var pastduecolor = IIF((currentdate > twodayslater)," ", "#BE2528")
When using the above #2, #3 work
var pastduecolor = IIF(!IsEmpty($datapoint.campclosedate) && (currentdate > twodayslater), " ", "#BE2528 ")
When using the above # 1, #2 work
var pastduecolor = When(IsEmpty($datapoint.campclosedate) && (currentdate > twodayslater), "#BE2528", IsEmpty($datapoint.firstpostda1) && IsEmpty($datapoint.campclosedate), " ", " ")
When using above #1, #2 work
Thank you very much,
Annette
Looking at your conditions, "postdate is empty" is present in both conditions 2 and 3. And then you are specifying checking whether or not there is a close date, but if I read your post correctly, you want the background to be blank whether or not there is a close date.
Put simply, I don't see the dstinction between #2 and #3 the way you're describing it.
Also, the result of those two conditions is to not apply any color. If we default the background color to being blank, then you really only need to adjust that value for cases where it matters. A successful execution of items 2 and 3 would be identical to nothing happening at all, right?
Iif($feature.postdate > 48, 'red', '')
Hello Josh,
You are correct, item 2 and 3, nothing happens. When I apply
var pastduecolor = IIF($datapoint.firstpostda1 > 48, "#BE2528", "")
it turns red if the postdate is past 48 hours and if there is a close date. If there is a close date, then no need to turn red. I am trying to add an "or" to the statement.
If post due date is > 48 hours turn red or if closed date is not empty, do nothing.
But I get "unexpected string"
var pastduecolor = IIF($datapoint.firstpostda1 > 48, "#BE2528", "") || IIF(!$datapoint.campclosedate), " ")
I also tried
var pastduecolor = IIF($datapoint.firstpostda1 > 48, "#BE2528", "") || IIF(!$datapoint.campclosedate), " ","")
I am thinking it has something to do with the parenthesis?
I don't know. Your help is always appreciated.
Thank you,
Annette
I realized I forgot to add IsEmpty. I added it
var pastduecolor = IIF($datapoint.firstpostda1 > 48, "#BE2528", "") || IIF(!IsEmpty($datapoint.campclosedate), " ","")
But now I get "Runtime Error: Operator || cannot be used. Only || or && are allowed values"
Which I don't understand. I am using the key above the enter key to input the ||. Should I use a different key?
Thank you,
Annette
Hi Annette,
Just back from 2 weeks' vacation. I think the trouble here is that "||" and "&&" are used for boolean conditions that can evaluate to "true" or "false", something like
$datapoint.firstpostda1 > 48 || !IsEmpty($datapoint.campclosedate)
But the iif function is returning strings, which won't evaluate properly. Also, when you have multiple conditions, linking them with || or && really only makes sense if they have a single outcome. "If A or B, do X". Where you have two conditions and two outcomes, these really need to be separated.
So, taking the "plain English" version of your conditions:
If post date is greater than 48 hours, turn red OR if camp close date is not empty turn green.
We could just write it like this:
var pastduecolor;
if ($datapoint.firstpostda1 > 48){
pastduecolor = "red"
} else if (!IsEmpty($datapoint.campclosedate)){
pastduecolor = "green"
}
Since these conditions aren't linked, the order matters. If the empty close date is more important than the other field, then just put it first.
Hello Josh,
I hope you had a great vacation. I have tried several ways to do this, but never quite right. I tried
var pastduecolor;
if(currentdate > twodayslater){
pastduecolor = "red"
} else if (!ISEmpty($datapoint.campclosedate)){
pastduecolor = "black"
}
return {
textColor: '',
backgroundColor: pastduecolor,
separatorColor: '#005ce6',
selectionColor: '',
selectionTextColor: '',
attributes: {
// attribute1:
}
}
What I am getting is
- when there is no post date and no close date, it should be black, but its red
-when there is a post date > 48 and a close date, it should be black, but its red
Those are my two issues. Basically the only item that works is post date > 48 hours turn red.
As you stated above "If post date is greater than 48 hours, turn red OR if camp close date is not empty turn black". Plus these other two caveats --
no post date, no close date = black
close date = black.
Any ideas? Thank you Josh.
Annette
Hello Josh @jcarlson ,
I thought this would work. If post date is greater than 48 hours, turn red OR if camp close date is not empty turn green. BUT I get an error "Parse Error:Line 22: Unexpected token return".
var pastduecolor = IIF($datapoint.firstpostda1 > 48, "#BE2528", "" || IIF(!IsEmpty($datapoint.campclosedate), " ","#BE25")
return {
textColor: '',
backgroundColor: pastduecolor,
separatorColor:'#005ce6',
selectionColor: '',
selectionTextColor: '',
attributes: {
attribute1: pastduecolor,
Thank you. Annette