setting a variable in a JavaScript while loop
Hi I'm creating a summary table and I have it working they way I want but it is a little long winded and I would like some help on shortening my code. Basically the resulting output is a 4 column table with
| Full Name | Email (work) | Work Phone | Mobile |
The contacts full name is a hyperlink to the contact, and I want the Email to be a mailto: link
what I'm having trouble with is setting the variable mail = @All of Email.filter(function (obj) { return obj.type === 'work'}).map(function (obj) { return obj.value})[i] in the middle of the while loop.
Here is the working code. If you could give me some suggestions on how to set the email value to the mail variable I would be greatly appreciative
var url = "https://podio.com/<organisation>/crm/apps/contacts/items/"
//var mail = ""
var markdownTable = "|Name |Email |Work |Mobile|";
markdownTable += "\n" + "|----------------|--------------|-------|----|";
for (i=0; i<@All of ContactID.length; i++) {
markdownTable += "\n |" + "[" + @All of Full name[i] + "]("+ url + @All of ContactID[i] + ")" + " | " +
"[" + @All of Email.filter(function (obj) { return obj.type === 'work'}).map(function (obj) { return obj.value})[i] + "](mailto:" + @All of Email.filter(function (obj) { return obj.type === 'work'}).map(function (obj) { return obj.value})[i] + ")" + " | " +
@All of Phone.filter(function (obj) { return obj.type === 'work'}).map(function (obj) { return obj.value})[i] + " |" +
@All of Phone.filter(function (obj) { return obj.type === 'mobile'}).map(function (obj) { return obj.value})[i] + " |"
};
write = markdownTable
Here is the result
-
Doh! Never mind I worked it out
var url = "https://podio.com/<organisation>/crm/apps/contacts/items/"
var mail = @All of Email.filter(function (obj) { return obj.type === 'work'}).map(function (obj) { return obj.value})
var markdownTable = "|Name |Email |Work |Mobile|";
markdownTable += "\n" + "|----------------|--------------|-------|----|";
for (i=0; i<@All of ContactID.length; i++) {
markdownTable += "\n |" + "[" + @All of Full name[i] + "]("+ url + @All of ContactID[i] + ")" + " | " +
"[" + mail[i] + "](mailto:" + mail[i] + ")" + " | " +
@All of Phone.filter(function (obj) { return obj.type === 'work'}).map(function (obj) { return obj.value})[i] + " |" +
@All of Phone.filter(function (obj) { return obj.type === 'mobile'}).map(function (obj) { return obj.value})[i] + " |"
};write = markdownTable
Please sign in to leave a comment.
Comments
1 comment