JS Formula if statement

Ask your questions here.
Post Reply
Flypz
Posts: 16
Joined: 27 Oct 2023, 15:38
Name: Zs
Location: UK

JS Formula if statement

Post by Flypz »

I'm trying to work with the JS formula inside my public form but I'm having issues with the syntax of the system.

[1087] is my global list where I have values assigned to each option.
[1098] is my base value which is calculated separately from the if statement.

The way it's currently set up is to use the global list option value to check if it's smaller than my set amount.

What I want to achieve is to check the option ID inside the global list and perform the action relevant to that ID instead of its value because that might be changed in the future.

My current code:

Code: Select all

my_function();
function my_function() {
  size = get_value([1087])
  
  if (size < 51) {
    return ([1098] * 0.010) + size
  } 
  else if (size < 101) {
    return ([1098] * 0.011) + size
  } 
  else if (size < 201) {
    return ([1098] * 0.012) + size
  } 
  else if (size < 301) {
    return ([1098] * 0.013) + size
  }

}
Example logic to what I want to achieve:

Code: Select all

my_function();
function my_function() {
  size = get_value([1087])
  
  if ([1087] = [380]) {
    return ([1098] +200) + size
  } 
  else if ([1087] = [381]) {
    return ([1098] / 3)
  } 
  else if ([1087] = [382]) {
    return ([1098] * 0.012) + size
  } 
  else if ([1087] = [1569]) {
    return ([1098] * 0.013) + size
  }

}
Global List.jpg
Post Reply