This article addresses the error encountered when a numeric field is populated with 'NaN' (Not a Number), potentially leading to records not saving.
Error Explanation
The 'NaN' value often arises from calculations or data entry errors and can stop records from saving, meaning the changes are only ever pending for the user who made the change. For instance, a 'NaN' value can be the result of a number expression dividing a number by zero.
Identifying NaN Errors
An error message may appear as follows:
An unexpected error occurred - SyntaxError: Unexpected token N in JSON at position 1612
Steps to Resolve NaN Errors
- Export the Data:
- Export your data to a CSV file and identify all records of 'NaN' across the relevant fields. This can be done by using 'ctrl + f' key shortcut
- Update Calculations:
- Once you know the field that has the 'NaN' you can then update that field. This can be done using conditional statements that check for a zero first and output the right value instead. Its also worth checking other fields that may be set up the same way, they may not error now but could in the future.
- Update NaN Records:
- Once you have published the change to the relevant fields, you can then go to the records you identified and re-run the expressions, this should happen when you resync the app but if not you can force the change by updating one of the fields used on the expression.
Example
For example, to correct the 'Completion' field, update the expression as follows:
Original Expression:
[QuestionsAnswered]/[TotalQuestions]
Updated Expression:
if([TotalQuestions]= 0, 0, [QuestionsAnswered]/[TotalQuestions])
This conditional statement checks if [TotalQuestions] is 0. If it is, the expression returns 0; otherwise, it performs the division as intended.
Comments
0 comments
Please sign in to leave a comment.