cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Community Tip - Did you get called away in the middle of writing a post? Don't worry you can find your unfinished post later in the Drafts section of your profile page. X

Sending a customized email from Thingworx

SM_10003989
3-Visitor

Sending a customized email from Thingworx

Hi All,

I need to send an email based on certain values by inserting html tags within the body. The tag code is ready but I am facing challenge in sending dynamic values within the tag. The values are different strings generated at runtime. Can anyone help me.

1 ACCEPTED SOLUTION

Accepted Solutions

@SM_10003989 ,

 

I'm not sure if Thingworx exposes any replace operations  for the XML object type (which is defined here: https://xerces.apache.org/xerces-j/apiDocs/org/apache/xerces/dom/DocumentImpl.html) .. I looked back at another post similar to yours and it looks like doing string concatenation or string replace is probably the easiest way to get there.  So, store your entire xml above as a string instead, and do a regex replace on your $[usergroups] token.

 

Hope that helps,

Nick

View solution in original post

4 REPLIES 4

@SM_10003989 ,

 

Can you show us an example of the code that you're using right now?  When I've had to create dynamic email bodies, I typically need to do a bunch of string concatenation.  I.e. 

var html = "<div id='mydiv'>" + myContent + "</div>";

 

Nick

Hi Nick,

I am using a template for the body. The template is stored in a static XML and parsed. Below is my template. I have to give the user groups in the $usergroups section node. I am getting the missing user groups from another service.

     <p>Hello,</p>

              <p><br></p>

              <p>Please note user groups below do not exist</p>

              <p>${usergroups}</p>

              <p>Users part of this AD Group won’t be able to login.</p>

              <p>Please take action</p>

              <p><br></p>

              <p>Thanks,</p>

              <p><br></p>

              <p>Support</p>
      

One the service that returns the missing user groups you can store this as a string with the desired XML tags if any. 

Then you can do a replace on your XML content like the following (regex may need adjustment)

 

let xmlString = getXmlTemplate();
let orgs = getMissingOrgs();
// process orgs into desired HTML structure
// if necessary

xmlString.replace( /\$\{usergroups\}/, orgs);

@SM_10003989 ,

 

I'm not sure if Thingworx exposes any replace operations  for the XML object type (which is defined here: https://xerces.apache.org/xerces-j/apiDocs/org/apache/xerces/dom/DocumentImpl.html) .. I looked back at another post similar to yours and it looks like doing string concatenation or string replace is probably the easiest way to get there.  So, store your entire xml above as a string instead, and do a regex replace on your $[usergroups] token.

 

Hope that helps,

Nick

Top Tags