1

Two condition nested If not working

I am trying to color a field when days overdue (delta_days) is the below however with the below code, I get either red or green, never Yellow. The second else/if should be skipped when the number for example is 50 (meaning 50 days until due) however it doesn't work. For debugging if I change the Green If portion to = 10 instead of >10, it skips the code which indicts it is functioning.

red = 0 or less

yellow = 1 - 10

green = 11 and higher

let days_delta := 'Due Date' - today();
let display_color := "yellow";
if days_delta <= 0 then
    display_color := "red"
else
    if days_delta > 10 then
        display_color := "green"
    end
end;
styled(text(days_delta), display_color)

7 replies

null
    • Ninox partner
    • RoSoft_Steven.1
    • 1 yr ago
    • Reported - view

    let days_delta := 'Due Date' - today();
    let display_color := if days_delta <= 0 then
            "red"
        else
            if days_delta > 10 then "green" else "orange" end
        end;
    styled(text(days_delta), display_color)

    • Holly_M
    • 1 yr ago
    • Reported - view

    Thanks and your code had the same result as displayed by the screen capture. What I did do is convert the date into a UTC number format and did the If statements against that and it worked with the code I posted. That tells me the coding is correct, and there perhaps is a bug?

     

    The working date change/code is the following:

    let days_delta_actual := 'Due Date' - today();

    let t_due_date := number('Due Date');

    let t_today := number(today());

    let days_delta := t_due_date - t_today;

    let display_color := "yellow";

    if days_delta >= 864000000 then

    display_color := "green"

    else

    if days_delta <= 0 then

    display_color := "red"

    end

    end;

    styled(text(days_delta_actual), display_color)

    • Fred
    • 1 yr ago
    • Reported - view
    Holly M said:
    That tells me the coding is correct, and there perhaps is a bug?

     Hi Holly

    Your code does not allow for the option of "yellow" to ever be the result. You have "yellow" outside your if statements so it will never be a result. Try:

    if days_delta >= 864000000 then
        display_color := "green"
    else
        if days_delta <= 0 then
            display_color := "red"
        else
            display_color := "yellow"
        end
    end;
    
    • Holly_M
    • 1 yr ago
    • Reported - view

    Thanks Fred and the code I pasted worked exactly as it should, and I tested it by changing the dates. You are correct that "yellow" is never addressed in the IF/ELSE statements so the initial Let statement which sets it to yellow would apply. Same result but I skipped the Else statement since it was already set to yellow.

    • Holly_M
    • 1 yr ago
    • Reported - view

    I should have added that while both the coding approached worked to get to a "Yellow" with the 1-10 days, it ONLY worked when the date was converted a number for the logic. Try that logic with the original approach against the math using the Dates only partially worked.

    • Fred
    • 1 yr ago
    • Reported - view

    I got focused on the wrong element of your code.

    Yes subtracting date fields is a bit confusing in Ninox. In the background, Ninox uses milliseconds to keep track of date/time fields, as you accounted for.

    You can use the days() function to give you a human understandable number.

    let days_delta := days('Due Date',today());
    let display_color := "yellow";
    if days_delta <= 0 then
        display_color := "red"
    else
        if days_delta > 10 then
            display_color := "green"
        end
    end;
    styled(text(days_delta), display_color)
    
    • Holly_M
    • 1 yr ago
    • Reported - view

    Thanks for the more understandable approach :-)

Content aside

  • Status Answered
  • 1 Likes
  • 1 yr agoLast active
  • 7Replies
  • 78Views
  • 3 Following