If condition not working with comparison operators
Hi,
I have got a headache trying to understand why can Ninox scripting engine comprehend such a simple If condition together with "and" and "or" operators:
let currentDate := today();
let invoiceDueDate := 'Due Date';
let currentInvoiceStatus := number('Invoice Status');
let overdueDays := days(invoiceDueDate, currentDate);
if overdueDays > 0 and (currentInvoiceStatus != 3 or currentInvoiceStatus != 5) then
styled(text(overdueDays), "#FF8FAE")
else
if currentInvoiceStatus = 1 then
styled(text(null), "#B7E3F1")
else
if currentInvoiceStatus = 2 then
styled(text(null), "#264EF9")
else
if currentInvoiceStatus = 3 then
styled(text(null), "#20C461")
else
if currentInvoiceStatus = 5 then
styled(text(null), "#F1CC08")
end
end
end
end
end
Requirement:
To display the number of days by which the invoice is overdue in case the overdueDays > 0 and currentInvoiceStatus is not Cleared or Cancelled.
Different Invoice Status:
1 - New, 2 - Sent, 3 - Cleared, 4 - Overdue and 5 - Cancelled
Result:
With the current code above, I am getting the overdue days in all the conditions no matter what (whether the currentInvoiceStatus is "New" or "Cancelled" or "Cleared" or "Paid" or "Overdue").
It should only show the overdue days if the currentInvoiceStatus is either "New" or "Sent". If the currentInvoiceStatus is "Cleared" or "Cancelled", the overdue days should be null.
Thanks,
Vermaji
--------------------------
18 replies
-
This example can be referred to..
-
Well I got this to work for me:
let currentDate := today(); let invoiceDueDate := 'Due Date'; let currentInvoiceStatus := number('Invoice Status'); let overdueDays := days(invoiceDueDate, currentDate); if overdueDays > 0 and currentInvoiceStatus != 3 and currentInvoiceStatus != 5 then styled(text(overdueDays), "#FF8FAE") else if currentInvoiceStatus = 1 then styled(text(null), "#B7E3F1") else if currentInvoiceStatus = 2 then styled(text(null), "#264EF9") else if currentInvoiceStatus = 3 then styled(text(null), "#20C461") else if currentInvoiceStatus = 5 then styled(text(null), "#F1CC08") end end end end end
I would've thought the 'or' would be the most appropriate way to write the code. I still get tripped up with this when I write my code. I guess the best way to remember is to think of it as a list of requirements so it is always an 'and'.
I want this to be true if:
variable doesn't equal 3
and
variable doesn't equal 5
and
-
I would second opinion to use a switch as it will make things easier to read and troubleshoot.
-
said:
Is it possible to hide the Table view when we open a database and go straight to the SwitchboardLook in the Options for the DB.
Content aside
- Status Answered
- 3 mths agoLast active
- 18Replies
- 62Views
-
4
Following