- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-15-2018 10:38 AM
Hi All,
I stumbled upon an error which acutally cannot be or there is indeed a bug. This is part of the code:
...
orderArr = grAtt.getElement('u_fields_order').getChoices() ; // array with order and choice values
gs.print(orderArr.toString());
gs.print(typeof(orderArr));
This part throws an error which says:
Javascript compiler exception: Invalid JavaScript value of type java.util.ArrayList (<refname>; line 17) in:
When I print out the array with gs.print(orderArr), I get:
[u_currency, u_phase, u_project, description, date, u_effort, u_unit, amount]
The quotes are missing. Is this a bug or is it me?
Solved! Go to Solution.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-19-2018 05:58 AM
Opened a HI Ticket and got following answer:
"[..] The return value of 'getChoices' method is an ArrayList as documented. [..]. "
KB0703680 - GlideElement - getChoices(String value)
So, you can use ArrayList's methods in this case. I've tested some methods like; arr.get(0), arr.size() and the methods provided actual results. There isn't any error in the returned values.
The error you've received is related to language-mismatch. 'typeof' is a JavaScript function and this function can only return the following values: 'undefined, object, boolean, number, string, symbol, function'. As seen, 'ArrayList' isn't present in this list because 'ArrayList' is a Java Class.
Therefore, encountering 'Invalid JavaScript value of type java.util.ArrayList' error after running 'typeof(arr)' is an expected behavior. I'd suggest not checking the type of the return value. You can assume getChoices() always returns an ArrayList-type value and you can perform your following actions accordingly."
Thanks!

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-15-2018 12:01 PM
Ok. I think you should be using
orderArr = grAtt.u_fields_order.getDisplayValue().split(',');
Please mark this response as correct or helpful if it assisted you with your question.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-19-2018 05:58 AM
Opened a HI Ticket and got following answer:
"[..] The return value of 'getChoices' method is an ArrayList as documented. [..]. "
KB0703680 - GlideElement - getChoices(String value)
So, you can use ArrayList's methods in this case. I've tested some methods like; arr.get(0), arr.size() and the methods provided actual results. There isn't any error in the returned values.
The error you've received is related to language-mismatch. 'typeof' is a JavaScript function and this function can only return the following values: 'undefined, object, boolean, number, string, symbol, function'. As seen, 'ArrayList' isn't present in this list because 'ArrayList' is a Java Class.
Therefore, encountering 'Invalid JavaScript value of type java.util.ArrayList' error after running 'typeof(arr)' is an expected behavior. I'd suggest not checking the type of the return value. You can assume getChoices() always returns an ArrayList-type value and you can perform your following actions accordingly."
Thanks!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-04-2019 10:28 AM
getChoices returns an ArrayList Java object - or maybe a JavaScript object that works the same way. Look up the Oracle documentation on ArrayList to see the available methods. getChoices will return the active choice values for the field. You can filter the returned choices by their dependent value by passing in the name of the dependent value like so:
current.some_field.getChoices("Some Dependent Value"); // returns a Java ArrayList full of active choices for the some_field field which are dependent on "Some Dependent Value"
From what I can tell, the ArrayList is full of strings that correspond to the value of the choice - at least if you are calling getChoices on a field with type <String>.