How can I determine type of a value?

+1 vote
asked Dec 2, 2015 by mike-r-7535 (13,740 points)

Can Qvera distinguish if a result value is numeric, and if so send the value to one field and if it is a date send to a different field? Also, if the value is text, send to a third, separate field?

For example, could be if I am querying a table or a csv field and three values where "Declined","03/08/1967","47"

1 Answer

+2 votes
Best answer

The following script will determine if the value is a number, a date, or just plain old text:

// isNumeric function was taken from
function isNumeric(n) {
   return !isNaN(parseFloat(n)) && isFinite(n);
var value = '' + source.getNode('/');
if (qie.deduceDate(value) !== null) { + " is a Date!");
} else if (isNumeric(value)) { + " is a Number");
} else { + " is plain old text.");

Here is the output for the following values you provided:

47 is a Number

03/08/1967 is a Date!

Declined is plain old text

answered Dec 2, 2015 by mike-r-7535 (13,740 points)
selected Dec 2, 2015 by brandon-w-8204
commented Dec 2, 2015 by rich-c-2789 (16,020 points)
There are cases where the data in a column may be dynamic...but this statement suggest that the source of the data may be consistent:

  "For example, could be if I am querying a table or a csv field and three values where "

Typically the results from a query or the content of a CSV is structured data.  Meaning that the columns should be consistent in the type of data contained in that column.  If the data in each column is consistent then you can access the column by name or index.  See this question for examples:

Structured data may contain values to represent null or unknown data.  In such cases testing for null or unknown before consuming the value may be a better fit.