Title
Strange "Validate Always" behavior with scripted variable…
Post
I will try to explain what happened in detail. I am hoping someone can explain WHY it is happening.
In a Table, we created a field, set to Number type, with validation set to "Always", and strict data type of Number.
We then set a Variable ($ID_List) in a script to a number (I know variable only hold text). Next we used the script step of "Set Field" to set the newly created number field to the value of the Variable "AS A NUMBER" using the calculation:
GetAsNumber ( $ID_List ).
Immediately we get an error code of 502 for validation issue.
STEP 2.
After much head scratching, we experimented by removing the strict data type of number from the field and left validation to "Always". Still failed.
STEP 3.
Set the variable to a text string and changed the table field to a data type of "Text". Left validation to "Always" and removed the strict data type of number. Everything works.
Can anyone explain why this is happening? I understand that variables only hold text and that numbers put into a variable are stored as text. When I use the function of "GetAsNumber ( $ID_List )" I expect the text numbers to be treated as actual numbers. Why isn't this working?
Interesting. I think you've found a bug that should be reported over in the Report an Issue section.
If I assign a single number to a variable, I can assign it to the validated number field and no error occurs.
Set variable [$Number ; value: 5 ]
Set Field [Table::NumberField ; $Number ]
If I enclose the number in quotes and assign it to the variable, I still do not get an error.
Set variable [$Number ; value: "5" ]
Set Field [Table::NumberField ; $Number ]
If I use List to assign a list of numbers, I get the error.
Set variable [$Number ; value: list ( 5 ; 4 ; 3 ) ]
Set Field [Table::NumberField ; $Number ]
That is all as expected. But if I use GetAsNumber to coerce the list of number values back into a single number of type number, I then get the error when I would not expect it.
Set variable [$Number ; value: list ( 5 ; 4 ; 3 ) ]
Set Field [Table::NumberField ; GetasNumber ( $Number ) ]
As a work around, the following works and also suggests that the FileMaker team needs to look at the returns that separate values in a list to see where the problem lies:
Set variable [$Number ; value: list ( 5 ; 4 ; 3 ) ]
Set Field [Table::NumberField ; getValue ( GetasNumber ( $Number ) ; 1 ) ]