gr.getElement('field').getChoices() give invalid Array

Tuna
Giga Guru

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?
1 ACCEPTED SOLUTION

Tuna
Giga Guru

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!

View solution in original post

7 REPLIES 7

SanjivMeher
Kilo Patron
Kilo Patron

I think you should just do

 

orderArr = grAtt.u_fields_order.getChoices() ;


Please mark this response as correct or helpful if it assisted you with your question.

I tried, but still getting same error.

Is that a Choice field?


Please mark this response as correct or helpful if it assisted you with your question.

It is a List field wich choices:

find_real_file.png

Where Choice values are column names as strings. getChoices() gives an array of these column names, but as I said, the Array is invalid and I can not iterate through it.