33 Posts
justintime
2 years ago
5
Topic

Hi everyone,

I need to use an "if" statement to return a value (red, amber or green) depending on a number that is computed (if the number is greater than 192 return the word Red.  I cannot find in the Forums, Manuals or Videos whether if statements can be used and if they can be what syntax should be used.

In my field (rating)  have tried to use (and several variations):

+if((a*b*c)>=192,"RED",+if((a*b*c)>=41,"AMBER","GREEN"))

I appreciate this is rather Excel like, but it is the best I have to go on.  I have a separate field (score) which return the value of a*b*c so I know that a value can be generated.

I have also noticed in the database table for my content type that the field score exists and contains a value, but the field rating does not exist in the table.

I would be grateful for any advice or help that anyone can offer please.

Thank you in advance.

Get a VIP membership
33 Posts
justintime
2 years ago
0
Level 1

UPDATE but your help is still required and appreciated:

I have simplified the statement to try to work out the syntax by setting a sinle parameter for field a being greater than the numeric value of 200.  I can get to the following before I get an error message:

If (a > 200) then 1 else 3

I then get an error message of “SyntaxError: unexpected token: numeric literal”.

33 Posts
justintime
2 years ago
1
Level 1

All, I am still looking for some help with this if any one is able?  Thanks JT

59 Posts
kobalt
2 years ago
0
Level 2

Hi justintime,

it depends on when the value is checked either before the form is displayed or while the form is being used.

In the first case


In the second case

  • you have to use javascript to change other field contents or their appearance. You should be very familiar with that and you can use it when there are no security-related things to do

best regards

33 Posts
justintime
2 years ago
1
Level 1

Kobalt,

Thank you for taking the time to respond to me.  Your response prompted two things:

  1. that my explanation of the issue was incomplete; and
  2. go back and look at this issue again.

I had already spent a couple of days on the issue before posting the question to the forum so was cautious about spending much more time on it without further guidance.  The resolution, as it happens, is actually reasonably straightforward and the main issue (once again) is a lack of documentation.

When editing a content type, you can select 5 to access the Conditional States and Computation.  All Seblod's documentation illustrates Computations using simplistic arithmetic operators +-*/.  My question was whether Computations could handle IF statements and if they could what syntax is followed.

Having looked at this again following your response Kobalt, and through a complete fluke when having experienced an Unexpected Token error found a Java article online.  I rewrote the if statement as

if ( a > 650) { result = 'Red'; } else { if ( a > 199) { result = 'Amber'; } else {result = 'Green'; }}

And it worked in my Content Type.  So the short answer is Computations can handle IF statements and the syntax follows Java.

The issue I face now is that in my List & Search form, no matter what the output is in the Content Type, the output in the List & Search form is the number 3. One step forward and two back as they say!

Thanks for your help Kobalt; it is appreciated.

JT

33 Posts
justintime
2 years ago
0
Level 2

Issue with the number 3 resolved; my stupidity!

Get a VIP membership