I want to add the item ‘%’ at the beginning of a value list so I use this code:
var arrayStatus = application.getValueListArray('status_off_acq');
arrayStatus.unshift('%');
But this code is not working, it says that “unshift is not a function”.
I noticed that the application.getValueListArray() function returns a NativeArray object (in my case is called org.mozilla.javascript.NativeArray@19f746) and not a regular Array object like [‘a’,‘b’,‘c’].
Is this a bug or should I handle NativeArray in a different way?
Hi Nicola,
Maybe you have to cast the variable to an Array.
var arrayStatus = application.getValueListArray('status_off_acq');
Array(arrayStatus).unshift('%');
Just thinking out loud ![Smile :)]()
Thanks for the reply Robert, this indeed eliminates the error but .unshift() does not yet work.
Here’s the full code:
var arrayStatus = application.getValueListArray('status_off_acq')
var arrayStatus2 = arrayStatus
Array(arrayStatus).unshift('Tutti');
Array(arrayStatus2).unshift('%');
application.setValueListItems('off_acq_righe_filtro_status',arrayStatus,arrayStatus2);
What I’m trying to do is really simple: I use a popup global field with a valueList attached as a Filter for some related data and I want to show “Tutti|%” (translation: “All|%”) as the first value of the list.
What about the following code?
var arrayStatus = Array(application.getValueListArray('status_off_acq'));
var arrayStatus2 = arrayStatus;
arrayStatus.unshift('Tutti');
arrayStatus2.unshift('%');
application.setValueListItems('off_acq_righe_filtro_status',arrayStatus,arrayStatus2);
ROCLASI:
What about the following code?
var arrayStatus = Array(application.getValueListArray('status_off_acq'));
var arrayStatus2 = arrayStatus;
arrayStatus.unshift(‘Tutti’);
arrayStatus2.unshift(‘%’);
application.setValueListItems(‘off_acq_righe_filtro_status’,arrayStatus,arrayStatus2);
Nope.
The result is a list like this:
Tutti
[org.mozilla.javascript.NatveArray@87aefa]
![Sad :(]()
Well I did some quick testing (instead of guessing
).
It seems that this VERY new function is not that polished.
var arrayStatus = application.getValueListArray('testvaluelist');
This results in a org.mozilla.javascript.NativeArray as shows in the debugger.
In fact in the debugger I can expand this variable and see the values inside this array.
application.output(arrayStatus.length);
This actually returns the correct count of values. 6 values in my case.
application.output(arrayStatus[0]);
However this returns NULL. (!?)
Casting the NativeArray to an Array results an array with 1 value. This is the Object itself.
My guess is that the getValueListArray() function returns a Java native array which is not compatible with JS arrays. No JavaScript Array functions can be used.
Maybe one of the Servoyans can comment on this ?
Btw this function is also not yet documented in the online help nor in the ServoyDevReferenceGuide2_2.pdf
But I know Marc Norman is working hard to catch up. ![Smile :)]()
It seems we arrived to the same conclusions… ![Wink :wink:]()
The docs and online help were my first stop, even before posting to the forum, I just hoped that someone knew how to handle NativeArrays…
Let’s wait for an official answer.