Skip to main content
Jun 16, 2022 3:38 PM UTC
Solved

Retrieve multiple email addresses from data table and insert as input into email service

I have a service where I retrieve one to many email addresses from my data table based on certain inputs. How do insert these into the send message service? It currently gives me the following error,

 

"javascript service. Message ::Invalid or malformed email address entered."

 

 

 

 

nmutterAnswer
Jun 26, 2022 6:50 PM UTC

I'm not so clear what you want to do as the code you provided seems to be missing some comments and brackets.

 

But creating a string like "email1;email2;email3;" for the SendMessage service you can just do

var tableLength = result.rows.length;
var emailReceivers = ""; // empty mail string
for (var x = 0; x < tableLength; x++) {
 var row = result.rows[x];
 emailReceivers += row.Email + ";"; // append "email;" to receivers
}

if (emailReceivers.length > 0)
 emailReceivers = emailReceivers.slice(0, -1); // remove last ;

Hope this helps.

7 replies

Jun 17, 2022 7:41 AM UTC

Article - "How to send an email to multiple recipients via ThingWorx Mail Extension": https://www.ptc.com/en/support/article/cs310001 

Jun 17, 2022 11:36 AM UTC
Thank you, but I need help on the for loop to go through my results from the data table and put the semicolon in between each result.
Jun 22, 2022 9:28 AM UTC

can you share some code so we can help with it?