5 Replies Latest reply on Jan 27, 2015 1:08 AM by schpa

# Performing a bunch of if calculations to find correct value with script

Hey!

So I'm currently making a script to get the corresponding suggested price for the amount of kilos in one order, and have therefore set the total kilo of that order in a global variable \$\$tw and I want to find the correct suggested kiloprice when so and so many kilos are chosen in the actual order.

These are the steps I use to find the right one:

If [\$\$tw ≤ 10]
Set Variable \$\$up; Value:tab_customerprices::_10]
Else if [10 < \$\$up ≤ 50]

Set Variable [\$\$up; Value:tab_customerprices::_50]
Else if [50 < \$\$up ≤ 75]
Set Variable [\$\$up; Value:tab_customerprices::_75]
and so and and so forth

and then setting that value into the orders unitprice field.

However, this for some reason only works to differ between less or equal to 10 and less or equal to 50, when the total kilo exceeds 50, 100, 300 or whatever, it just takes the data from the _50 field and sets that into the unitprice field.

Any ideas?

And yea, I wrote half of the past in cursive, I have no idea how that and I couldn't figure out how to change it back so I just left it like that, hopefulle not too bothersome, hehe, but it has no meaning.

Thanks!

Simen

• ###### 1. Re: Performing a bunch of if calculations to find correct value with script

schpa wrote:

10 < \$\$up ≤ 50

FM does not support this syntax.  Use

\$\$up > 10 and \$\$up <= 50

• ###### 2. Re: Performing a bunch of if calculations to find correct value with script

Ahh, of course, thanks I'll try that out now.

• ###### 3. Re: Performing a bunch of if calculations to find correct value with script
Aaaaaand it worked :)
• ###### 4. Re: Performing a bunch of if calculations to find correct value with script

What Wim said.

Also, the test in this form in an End If []

10 < \$\$up and \$\$up ≤ 50

is not necessary; if you have reached that point, you already know that \$\$up is larger 10.

And lastly, unless you need to be very explicit in your script, you can use a single

Set Variable [ \$\$up ; with the calculation

Case (

\$\$tw ≤ 10 ; tab_customerprices::_10 ;

\$\$up ≤ 50 ; tab_customerprices::_50 ;

\$\$up ≤ 75 ; tab_customerprices::_75

// and so and and so forth

)

where Case() uses the result of the first test that evaluates as True (same as If[] / Else If[]).

(For some reason, your description only mentions one \$\$var, but your code has two …)

• ###### 5. Re: Performing a bunch of if calculations to find correct value with script

Thanks for the tip! Now my script works so I don't see a reason to change it now, but I'll definitely use that tip to make it easier in the future, I'm actually making a script that now that will automatically calculate field related to the field being changed when you exit it with a Get ( ActiveFieldName ) variable performing the calculations for the respective fields in the correct order when x field is changed, I'll try out the Case step then

And yea, hehe, the last bit was a typo on my hand, I don't know how to copy a script out of FM so I just wrote it down as best as I could, ended up with a bit too many \$up calculations, hehe, but the actual script doesn't look that way, luckily I

Speaking of, now that I'm on the topic and got your attention, do you by any chance know if it works to perform a step:

If [\$field = FieldName]
Set Field [FieldName; Field 1 * Field 2]

Or will I have to use the insert calculation step?

Because right now, this doesn't do the trick for me.

Edit: nevermind, I figured it out

The fault was in my if step, \$field = "FieldName" did it, previously I had \$field = TableName::FieldName.