Email fields. How to call in a calculation?

Hey everyone,

There are two ways to collect email addresses

  • with the email block
  • with a single line text block

I’m looking for clarity as to when using the email block is a better idea. Historically, I have always used the single line text block but I am noticing that on import, my data came in using the email block.

The above is a screenshot from a “clients” app. I am calling the email field in an related estimate app. The estimate as an “optional email” field in case we need to email someone who is not the primary contact.

If I call the [@all of client email] field nothis is rendered, even though there is an email contained.

1 Like

In the process of writing this up I was able to solve my own problem. I decided to post anyway so everyone can reference it in the future.

You need to add the following after your [@all of email field]

.map(function (obj) { return obj.value}).join()

1 Like

Is there a way to return the first email address when there are multiple in the email field?

Hi @1F2Ns,

glad to hear you were able to figure this out - it’s indeed not too easy as the email field is provided as an array of objects to allow more complex manipulations inside the calculation field.

Let me give you some code examples; You already figured out how to show all email addresses.

In order to show only the first one, just use [0] instead of .join(...):

You could also use the additional info to yield the first work email address:

The final result would look like this:

Hope that helps!

PS: A simple and effective debugging advice for calculation fields: You may use JSON.stringify() to stringify any available token and see what value it has at runtime. The output is rather technical and not user friendly, but can help to solve issues and debug more quickly.

1 Like

Thank you sir

I have a very broken understanding of JavaScript as most of what I’ve done over the years has been in PHP, HTML, and CSS.

1 Like