I have a script that sends some data to a REST service to compute the differences between three numbers and then return an average. That part really is not important I don't think, but I want to be complete.
The service returns 0.5 as one result into a variable called "$pairWiseAvg".
Then in the FMP Script, I have code like this:
If [ GetAsNumber($pairWiseAvg) <=0 ]
Set Field blah with this (THIS LINE EXECUTES!)
Else
Set Field blah with that
End If
--
Now, in the FMP debugger, I confirm that the value returned is 0.5
But, FileMaker runs the first part of the IF statement even though 0.5 is not less than 0.
What am I missing?
Thanks
Your computer uses comma or dot as decimal separator?
2 Likes
Standard American computing, a dot.
This example JavaScript is correct:
let value = .5
if (value <= 0)
{
console.log("less than or equal to zero");
} else
{
console.log("greater than zero");
}
Prints: "greater than zero"
Hello @OliverBarrett
Might it be possible to share a screenshot of the script ?
Perhaps if we see the script we might be able to spot some nuance that results in the unexpected result that you see. As an example, a mis-spelled variable name could possibly yield the result that you are seeing.
Very best,
-Steve
p.s. I note that, in your screenshot of the Data Viewer, the value has not yet been converted to a number data type, because it is displaying with a trailing '0' char, which, of course, would happen for data type text, but not number.
2 Likes
GetAsNumber("0.5") <= 0
and
GetAsNumber("0,5") <= 0
both give zero here.
The GetAsNumber("0.5")
gives me a 5 and GetAsNumber("0,5")
gives me a ,5 as I use comma for decimal separator.
What is $pairWiseAvg?
Is it a text, a list, a container value?
GetAsNumber("") <=0
this returns 1 for me, so variable may be empty?
1 Like
Great idea, Steve. Thanks.
Here's the script:
The weird thing is that the IF statement works fine if the number returned > 1.
I believe the GetAsNumber() in the script above takes care of the text .50 result.
Thanks again.
AFAIK, REST can only return text result but, in this case, it's a single text result returned value after computation.
The basic computation in the service is for when you want to say, estimate how long something is going to take from recent values.
Use-case: estimate how long before disk space exhaustion:
Say you have these three values for disk space:
50
48
37
The average difference between them, and the value returned, is ((50-48) + (48-37))/2 = 6.5
If these are weekly values, we could estimate you have 37/6.5 weeks left before disk full (less than six weeks).
That's all this script is really doing. I just used the REST service since it's already part of our library.
So in this context, the 6.5 would be what was returned, not the 0.5. And, strangely, the 6.5 works fine in the IF statement.
???
Thx
@OliverBarrett
I'd take a close look at the IF condition.
It appears to me that the closing ')' char is in the wrong place.
-Steve
4 Likes
I figured it out!
My closed parenthesis was in the wrong place with GetAsNumber()
Thanks to all.
4 Likes
LOL..we were typing this answer at the same time!
Thanks Steve!
1 Like