use array to get related fields.

Comments

10 comments

  • Kent Watson

    Hi,

    I'm not sure I understand your question.  Do you want to see as text, values for all your fields in a separate calculated field? e.g.

    field1: value 1
    field2: value 2
    field3: value 3

    etc
    0
    Comment actions Permalink
  • Rainer Grabowski

    I think, you've 2 options:

    First: 
    In the field GörevArray create a simple string like:

    @Date + "|x|"+ @Text + "|x|" + @Category

    As separators between the fields take a string which is unique (e.g which would never appear in a text).

    Then in the other app:

    var a = @All of GörevArray;
    var r = []
    for(var i = 0; i < a.length; i++){
    elemSplit = a[i].split("|x|");
    date = elemSplit[0];
    text= elemSplit[1];
    category = elemSplit[2];
    r.push(category);
    };
    r.join()

    or shorter

    var a = @All of GörevArray;
    var r = []
    for(var i = 0; i < a.length; i++){
    elemSplit = a[i].split("|x|");
    r.push(elemSplit[2]);
    };
    r.join()

    or 

    var a = @All of GörevArray;
    var text = 0;
    var date = 1;
    var category = 2;
    var r = []
    for(var i = 0; i < a.length; i++){
    elemSplit = a[i].split("|x|");
    r.push(elemSplit[category]);
    };
    r.join()

    The second option is using JSON:

    In the field GörevArray create a JSON-string like:

    JSON.stringify({"text": @Text, "date": @Date, "category": @Category})

    Then in the other app:

    var a = @All of GörevArray;
    var output = ""
    var r = [];
    try {
    for(var i=0; i < a.length; i++) {
    aElem = JSON.parse(a[i]);
    output = aElem.text;
    if(output != null){
    r.push(output);
    }
    }
    } catch (e) {
    output += e;
    output = 'Could not parse JSON';
    };
    r.join()

    Try and Catch are necessary cause a Podio calculation fields needs that (s. here https://help.podio.com/hc/en-us/community/posts/202620823/comments/207048117 )

    Rainer
    rg@delos-consulting.com

     

    0
    Comment actions Permalink
  • mvm Top Management

    Rainer Hi, thanks for your help, we are in same way. i also tried solutions in link that u gave.
    But i ve got some issues.

    First of all, i use JSON solution, its more simple to do. Because there is many string to collect.

    Result is expected. There isnt any problem.

     

    But icouldnt find the problem in second part.

    in another way, i try the other code. it works clearly.

    But let me know, how can i define the result a string.

    thanks for your help.

    this code will make my work easier and will save my time.

     

     

    0
    Comment actions Permalink
  • Rainer Grabowski

    Hi,

    in deneme2 it must be r.push(), not b.push().
    Pro-tip: Don't just copy and paste - but check what you copy :)

    The error in the last image says what's wrong: You can't use var b = try ..
    Just think :)  - cause you have the solution: You don't need the var b.
    Take the code from the last but one image, add var c = 10; a+c.That's all.

    Rainer

    0
    Comment actions Permalink
  • mvm Top Management

    Rainer, hi again.

    I m not a coder, and im trying to learn JS from beginning to use Podio more effective.
    I think im good at it :) But these JSON lesson is more complex for just now. I really dont understand its logic.

    Here is the results after your guidance.

    I couldnt figure out first code. It gives only one result from array.

    But i solve it the second one and i made an improvement for it. maybe it will be helpful for more Podio Users, so im sharing it.

    First field, for collecting strings for array:

    i changed the |x| indicator.to ß Because its a markdown and get blot the view. 



    Second field for split. Main change is here. Not for a one result, for calling all result easily, code take all splited parts in an array. So, i can call them like r[1] , r[2] , r[..n].

     

    Thanks for your help.

     

     

     

    0
    Comment actions Permalink
  • Rainer Grabowski

    Hi,

    great that it works for you. But I'm curious how it can work. One thing I don't understand: Cause .length always returns a number, the result of the calculation in your first image must be in my opition something like:


     Also the second calculation I don't understand, but that's maybe I don't know what's in var a (how a string a.join() would look like). Btw: r.join() is superflous in your code, it does nothing, cause r[4] follows. 

    Rainer

    0
    Comment actions Permalink
  • mvm Top Management

    last sentenced is wrong in your code Rainer.

    it must be:

    for(var i=0; i<A1.length; i++){
    AR+=A1[i] +"ß";
    }

     

    second part,
    r[4] may change with lenght. in your array there are 3 str. so r[4] couldnt work. but i have 81 field in array.

     

    0
    Comment actions Permalink
  • Rainer Grabowski

    Yes, A1[i] is my bad, sorry. I didn't use [r4], I only quoted your code, where r .join() is superflous.

    You whole code can be shortened to 2 lines:
    In Calculation field "Array":

    @field1 + "ß" + @field2 + "ß" + @field3

    In Calculation field 2:

    @all of Array[0].split("ß")[3]

    In field Array you can also use:   

    A1 = [@field1,@field2,@field3]
    AR1 = ""
    for(var i = 0; i < A1.length; i++){
    AR1+=A1[i]+"ß";
    }; 

    If you get an error notification in field 2:

    String(@all of Array[0].split("ß")[3])

    The codes I've provided some days ago have been for multiple related items. But it seems, you only need it for one related item. and that can be done by 2 lines of code.

    Rainer

      

     

    0
    Comment actions Permalink
  • mvm Top Management

    Ok, your opinion is important for me. so, im go back to your JSON code.

    i really couldnt figure out the problem with it.

     

    first field:

    its ok. nothing different with yours.

    and, inotherapp, the second field:

    result is 0 ?

     

     

    i tried smtgh for solution. disable aElem.text;

    result is:

     

    i removed ".text" afet aElem;

    result is:

     

    how can i solve the problem? :/

     

    thanks for your help.

     

     

     

     

     

     

     

     

    0
    Comment actions Permalink
  • Rainer Grabowski

    Hi, 

    as I've said: Don't simply copy :)
    I've used this example JSON. 

    JSON.stringify({"text": @Text, "date": @Date, "category": @Category})

    The pair

    "text": @text  

    is called a Property, "text" is the (property) name,@text the (property) value.
    To get the value you have to call the name - that you do in the line 

     output = aElem.text;

    (where aElem is the object name; the object stores the properties):
    Your mistake: You have copied the property name "text" from my example, but you don't have a property name "text" in your JSON. Change "text" to one of your property names and you'll get the value. 

    But if you have only one related item, you can also use the more simple @all of array.split() method which I've explained in my last posting.

    Rainer

    0
    Comment actions Permalink

Please sign in to leave a comment.

Powered by Zendesk