Problem with arrays



  • Jacquelyn May

    Hi Marcos,

    I think it would be helpful if you include your full code, so others can see what might be causing the problem :)

    /Jacquelyn - Podio

    Comment actions Permalink
  • Adil Tuncer

    Hi Marcos, did you solve the problem?

    I have the same problem. Here is my code:

    ///code begins

    var arr = [];

    for (var i = 0; i < @All of years.length; i++) {
    arr.push(@All of years[i]);

    ///code ends

    1. arr[0] gives 2012, it is OK.
    2. arr[1], or arr[2], etc  gives "the script returned an undefined result" 
    3. @All of years.length gives 4.
    Comment actions Permalink
  • Marc Høegh

    Hi Adil,

    This is most likely due to the fact that the sample value that Podio uses for `@All of years` is an array containing just a single item.

    You will therefore have to handle the case where the index that you're accessing in the array is out of bounds. Like so:

    arr[38] || null

    Depending on what kind of value your calculation field is returning, you may return your own appropriate default value such as:

    arr[38] || 'Could not calculate value'

    For a calc field returning a string. Or:

    arr[38] || 10

    For a calc field returning a number.

    Hope that makes sense.

    Comment actions Permalink
  • Adil Tuncer

    Hi Marc,

    Thanks for info.

    I dont know how, but following code worked for me.

    var arr = [];

    for (var i = 0; i < @All of Year.length; i++) {
    if (@All of Year[i]!="") {arr.push(@All of Year[i])}

    var sml = arr[0];
    var big = arr[0];

    for(var i=0; i< arr.length; i++)
    if(arr[i] > big)
    big = arr[i];
    else if (arr[i] < sml)
    sml = arr[i];

    var lastyear= Number(big)

    Comment actions Permalink
  • Colin Brown

    I've run into a similar problem, and Marc didn't answer the issue here.

    Lets say i have defined `var arr = @all of created on`

    I know how many items there are in the referenced app, and sure enough, arr.length returns that number.

    However, attempting to call specific parts of the array fails:

    arr[0] - returns a result

    arr[1] - the script returned an undefined result

    arr[2] - the script returned an undefined result

    arr[n] - the script returned an undefined result


    I would expect this if n was greater than arr.length-1, but it's not!


    Also of interest: arr.join(",") does return (in the preview area) the expected string of all values.

    I've tested this with a variety of fields (not just 'created on', but also string and number fields), and I've done so in brand new calc fields (to avoid data type error). That said, I've also had times when this problem doesn't exist, so i'm really not sure what circumstances are causing it.


    Comment actions Permalink
  • Rainer Grabowski

    Hi Colin,

    for whatever reason: The calculation fields show only the first arr[0] and the last element arr[arr.length -1 ] w/o making them a string. All the other elements you get by using:



    Comment actions Permalink

Please sign in to leave a comment.

Powered by Zendesk