FORUM PLAN UPDATE
Date revision: This forum will remain open to new posts and responses until December 1, 2018. (After that date, you will still be able to view and search the forum.) Also, we're taking a second look at the best place to host future conversation. For now, keep using this forum, and stay tuned for more news.



Mar 10, 2012, 2:10 AM
46 Posts

'range' is undefined and cannot be accessed as an array

  • Category: Server Side JavaScript
  • Platform: Windows
  • Release: 8.5.2
  • Role:
  • Tags:
  • Replies: 4
Hi, I have a problem with javascript.
The strange thing is that there is this error when I run the application on localhost - appears only on the production server

Exception

Error while executing JavaScript computed expression
Script interpreter error, line=10, col=14: 'range' is undefined and cannot be accessed as an array

JavaScript code

   1: var range = @DbColumn("","data",1);
   2: 
   3:     function rand(range_from,range_to)
   4:         {
   5:             var r = Math.random();
   6:             r = r * (range_to-range_from) + range_from;
   7:             return Math.round(r);
   8:         }
   9: 
  10: var result = range[rand(0,range.length-1)];
  11: 
  12: return result
Mar 12, 2012, 6:52 AM
272 Posts
Re: 'range' is undefined and cannot be accessed as an array
Hi,
 
you are trying to access a undefined value, that is why it is not working. 
Maybe the lookup is not correct. Please check your @DBColumn: Is the view existing / a view index build?
 
Hope this helps 
Sven
 
Mar 13, 2012, 10:21 AM
46 Posts
Re: 'range' is undefined and cannot be accessed as an array
Everything seems to be correct.
Is there another way to get a random value from a column?
 
Mar 13, 2012, 11:46 AM
272 Posts
Re: 'range' is undefined and cannot be accessed as an array
Script interpreter error, line=10, col=14: 'range' is undefined and cannot be accessed as an array
 
This happens if @DbColumn has no returning value.
 
Sven
 
Mar 23, 2012, 10:15 AM
46 Posts
Re: 'range' is undefined and cannot be accessed as an array
In the column, there are some values.
The strange thing is that the error only occurs on the server.

FORUM PLAN UPDATE
Date revision: This forum will remain open to new posts and responses until December 1, 2018. (After that date, you will still be able to view and search the forum.) Also, we're taking a second look at the best place to host future conversation. For now, keep using this forum, and stay tuned for more news.