Community Tip - Did you know you can set a signature that will be added to all your posts? Set it here! X
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.
Solved! Go to Solution.
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
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);
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