Painscript Script - cast String as Int?


(Steve Flook) #1

We have a mapping issue that will be addressed soon for a field that should be an int but is presently a string. All values in the index should cast cleanly.

Anyhow, in a pinch I wanted to aggregate some data on the field and thought creating a scripted field in K5 would be a temp solution. Can anyone point me in the right direction or provide a code example? I tried several things including (int)['doc.myfield'].value and also parseInt(string) as documented at https://docs.oracle.com/javase/8/docs/api/java/lang/Integer.html#parseInt%2Djava.lang.String%2D.

Is type casting a String to Int supported in either of the 3 scripting languages listed in K5?


(Chris Roberson) #2

Hi Steve,

Try:

Integer.parseInt(doc['myfield'].value)

Thanks


(Steve Flook) #3

That worked like a champ - thanks Chris!


(system) #4

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.