Pulling data out of a relation field

Comments

6 comments

  • Rainer Grabowski

    Hi Michaël,

    var a = @All of Telefoon;
    var b = @All of E-mail;
    var list = [];
    for(var i = 0; i < a.length; i++){
    list.push("E-mail: " + b[i].map(function (obj) { return obj.value }).join() + "\nTel: " + a[i].map(function (obj) { return obj.value }).join());
    };
    list.join("\n\n")

    Rainer

    0
    Comment actions Permalink
  • Michaël Struelens

    Hey Rainer, 

    thanks for the reply. 

    I've tried the code but my calculation field is giving an error.

    Kind regards,

     

    0
    Comment actions Permalink
  • Rainer Grabowski

    The code works correctly only if all phone fields have the same number of phone numbers (e.g. all 1) and all email fields the same of email addresses (e.g all 1). If one  field has 2 entries or is empty the code doesn't work. The following code should cover all cases:

    var a = @All of Telefoon with nulls;
    var b = @All of E-mail with nulls;

    var list = [];
    for(var i = 0; i < a.length; i++){

    aCheck = a[i][0] != null ? a[i].map(function (obj) { return obj.value }).join() : "--";
    bCheck = b[i][0] != null ? b[i].map(function (obj) { return obj.value }).join() : "--" ;

    list.push("E-mail: " + bCheck + "\nTel: " +aCheck);
    };

    list.join("\n\n")

    Rainer

    0
    Comment actions Permalink
  • Michaël Struelens

    Hi Rainer,

    Thanks! It works like a dream now. 

    have a nice weekend.

    Kind regards,

    Michael

    0
    Comment actions Permalink
  • Gus H.

    Hi Rainer. I was playing with you code and at the same time adding another field. Your two field entry works like a charm, but once I try inserting a third one, I get a script error. Any suggestions? Thanks as always.

    0
    Comment actions Permalink
  • Rainer Grabowski

    Hi Gus, 

    you can't use .map(function()) for var a (Full Name).  Instead of .map(function())  simply use .join() for var a.

    Rainer

    0
    Comment actions Permalink

Please sign in to leave a comment.

Powered by Zendesk