Post

2 followers Follow
0
Avatar

Company with multiple contacts

I got an app called company, which can have relations to multiple contact persons withon that company. I have written som code which can make a contact summary if there is only one contact person within the company. So how do i acces one relations information at a time?

Christian Kuke Marslev

Please sign in to leave a comment.

1 comment

0
Avatar

Hi Christian,

when you pull the information from the contact you do it with @all of name (for example). THis returns a so called array where the names of the contact are an element each.
arrName = [Name 1, Name 2, Name 3] = 3 elements in an [array].
The same happens for @all of phone 
arrPhone = [Phone 1, Phone 2, Phone 3].

To combine Name1 with Phone 1 etc. you need to "loop" through the arrays and pick from each arr first the first elemens, then in the next loop the second elements etc.   This way you create new array ("result" in my example) where each element is the combination of [Name 1 | Phone 1, Name 2 | Phone 2, etc.]

result = [];
for(i = 0; i < arrName.length; i++){
result.push(arrName[i] + " | " + arrPhone[i]);
};
result.join("\n")

The result of this code would be 3 lines:
Name 1 | Phone 1
Name 2 | Phone 2 
Name 3 | Phone 3

You have multiple options how you would like to display the result: As a table, as a simple list, as a numbered list, as a split list like
Name 1:
Phone 1
Email 1

Name 2:
Phone 2
Email 2

Rainer

Rainer Grabowski 0 votes