<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Email Event Handler - support for multistate and binary values]]></title><description><![CDATA[<p dir="auto">MangoGT 3.7.7<br />
How to make an Event Handler to email rendered multistate values and binary points please?<br />
At the moment multistate data point returns raw value and binary blocks emails from sending altogether (errors in .ma file).</p>
<p dir="auto">.ma file :</p>
<pre><code>ERROR 2021-05-04T09:27:34,289 (com.serotonin.m2m2.rt.event.handlers.EmailHandlerRT.sendEmail:468) - Error sending email 
java.lang.NullPointerException: null
	at com.serotonin.m2m2.rt.event.handlers.EmailHandlerRT.sendEmail(EmailHandlerRT.java:292) ~[mango-3.7.7.jar:?]
	at com.serotonin.m2m2.rt.event.handlers.EmailHandlerRT.sendEmail(EmailHandlerRT.java:208) ~[mango-3.7.7.jar:?]
	at com.serotonin.m2m2.rt.event.handlers.EmailHandlerRT.scheduleTimeout(EmailHandlerRT.java:165) ~[mango-3.7.7.jar:?]
	at com.serotonin.m2m2.rt.event.handlers.EmailHandlerRT.scheduleTimeout(EmailHandlerRT.java:79) ~[mango-3.7.7.jar:?]
	at com.serotonin.m2m2.util.timeout.ModelTimeoutTask.run(ModelTimeoutTask.java:36) ~[mango-3.7.7.jar:?]
	at com.serotonin.timer.Task.runTask(Task.java:179) ~[mango-3.7.7.jar:?]
	at com.serotonin.timer.TaskWrapper.run(TaskWrapper.java:23) ~[mango-3.7.7.jar:?]
	at com.serotonin.timer.OrderedThreadPoolExecutor$OrderedTaskCollection.run(OrderedThreadPoolExecutor.java:314) ~[mango-3.7.7.jar:?]
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128) ~[?:?]
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628) ~[?:?]
	at java.lang.Thread.run(Thread.java:830) [?:?]
</code></pre>
]]></description><link>https://forum.mango-os.com/topic/5174/email-event-handler-support-for-multistate-and-binary-values</link><generator>RSS for Node</generator><lastBuildDate>Sat, 17 Oct 2026 03:15:01 GMT</lastBuildDate><atom:link href="https://forum.mango-os.com/topic/5174.rss" rel="self" type="application/rss+xml"/><pubDate>Wed, 05 May 2021 01:00:16 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Email Event Handler - support for multistate and binary values on Thu, 06 May 2021 03:36:28 GMT]]></title><description><![CDATA[<p dir="auto">Here is something I have written for you to pull the rendered text values for binary and multistate points.</p>
<p dir="auto">Now you can use the created object to "map" your current values to their rendered text equivalents...<br />
If you don't understand how this works, feel free to yell out.</p>
<pre><code>var rql="or(";
 var items=[]
 //Get all points attached to the script context
 for(var i in CONTEXT_POINTS)
 {
    items.push('eq(xid,'+this[ i].getDataPointWrapper().xid+')');
 }
 //Build RQL query
 rql+=items.join(',') + ')';
 
 //get configs of all of these points
 var dataPoints=JSON.parse(JsonEmport.dataPointQuery(rql)).dataPoints;
 var ptMap={};
 //Iterate through to get the rendered values
 for(var i=0;i&lt;dataPoints.length;i++)
 {
    ptMap[ dataPoints[ i ].xid ] = {};
    if(dataPoints[i ].textRenderer.type==="BINARY")
    {
        //Set Binary renderedValues
        ptMap[ dataPoints[ i].xid ][0] = dataPoints[ i].textRenderer.zeroLabel;
        ptMap[ dataPoints[i ].xid ][1] = dataPoints[i ].textRenderer.oneLabel;
    }
    else if(dataPoints[i ].textRenderer.type==="MULTISTATE")
    {
        //Or get the multistate values
        for(var j=0;j&lt;dataPoints[i ].textRenderer.multistateValues.length;j++)
        {
            ptMap[ dataPoints[i ].xid ][dataPoints[ i].textRenderer.multistateValues[j].key] = dataPoints[ i].textRenderer.multistateValues[j].text;
        }
    }
 }
 //Print here just to show format of mapping. Can comment out.
 print(JSON.stringify(ptMap) ); //so ptMap[xid][ ptValue ] =&gt; renderedValue
 
</code></pre>
<p dir="auto">Fox</p>
]]></description><link>https://forum.mango-os.com/post/26616</link><guid isPermaLink="true">https://forum.mango-os.com/post/26616</guid><dc:creator><![CDATA[MattFox]]></dc:creator><pubDate>Thu, 06 May 2021 03:36:28 GMT</pubDate></item><item><title><![CDATA[Reply to Email Event Handler - support for multistate and binary values on Wed, 05 May 2021 14:15:02 GMT]]></title><description><![CDATA[<p dir="auto">Both 'renderedValue' and 'rendered' return 'undefined' in email unfortunately.</p>
<p dir="auto">Would you be able to help with the script please?</p>
]]></description><link>https://forum.mango-os.com/post/26613</link><guid isPermaLink="true">https://forum.mango-os.com/post/26613</guid><dc:creator><![CDATA[Elena]]></dc:creator><pubDate>Wed, 05 May 2021 14:15:02 GMT</pubDate></item><item><title><![CDATA[Reply to Email Event Handler - support for multistate and binary values on Wed, 05 May 2021 10:25:02 GMT]]></title><description><![CDATA[<p dir="auto">Look at this code for a script which fires an email using the email handler directly:<br />
<a href="https://forum.mango-os.com/topic/3147/email-last-day-s-events/2">https://forum.mango-os.com/topic/3147/email-last-day-s-events/2</a></p>
<p dir="auto">You should either use freemarker markup ie <code>&lt;#if value == 1&gt;Alt&lt;/#if&gt;</code><br />
or append to your freemarker object the renderedValue for each item as you iterate through them at the given time.</p>
<blockquote>
<p dir="auto">model.put("p1",p1.value)</p>
<p dir="auto">model.put("p2",p2.value)</p>
</blockquote>
<p dir="auto">However, looking at above, you're <em>'putting'</em> <code>p1.value</code>, not <code>p1.renderedValue</code><br />
EDIT: that might actually be <code>.rendered</code> not renderedValue!<br />
Try that first and if no luck then perhaps building on a script that gives a better defined message using pointLocator data inside the datapoint itself for multistate values.</p>
<p dir="auto">Fox</p>
]]></description><link>https://forum.mango-os.com/post/26610</link><guid isPermaLink="true">https://forum.mango-os.com/post/26610</guid><dc:creator><![CDATA[MattFox]]></dc:creator><pubDate>Wed, 05 May 2021 10:25:02 GMT</pubDate></item><item><title><![CDATA[Reply to Email Event Handler - support for multistate and binary values on Wed, 05 May 2021 09:12:06 GMT]]></title><description><![CDATA[<p dir="auto">thanks Matt.</p>
<p dir="auto">more context...<br />
We've got event handlers, and they are working fine.</p>
<p dir="auto">But now we need to enhance the emails to show a bit more data at the time of the event, thus populate some data points values into the email e.g.<br />
State (multistate type data point with 15 rendered values e.g. 1=Ready, 2=Fault etc) or<br />
Alarm (binary type, 0=Inactive, 1=Active).</p>
<p dir="auto">I'm defining these data points in Event Handler Script:</p>
<pre><code>model.put("p1",p1.value)
model.put("p2",p2.value)
</code></pre>
<p dir="auto">and adding code into Custom Email Template:</p>
<pre><code>&lt;table&gt;
&lt;tr&gt;
&lt;th&gt;State&lt;/th&gt;
&lt;td&gt;${p1}&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;th&gt;Alarm&lt;/th&gt;
&lt;td&gt;${p2}&lt;/td&gt;
&lt;/tr&gt;
&lt;/table&gt;
</code></pre>
<p dir="auto">result as per initial post:<br />
when only multistate data point defined in the code above, I'm getting an email and it contains State value as '1', not as I would expect - 'Ready'<br />
<img src="https://camo.nodebb.org/2eddf1f244cf9574cdd3d08a3b15f990f82f76d8?url=https%3A%2F%2Fi.imgur.com%2FSMrjuJD.png" alt="65d6896e-a4fa-47cb-9ca8-9a3543739deb-image.png" class=" img-fluid img-markdown" /></p>
<p dir="auto">and when binary data point is in the code - email is not getting send</p>
]]></description><link>https://forum.mango-os.com/post/26609</link><guid isPermaLink="true">https://forum.mango-os.com/post/26609</guid><dc:creator><![CDATA[Elena]]></dc:creator><pubDate>Wed, 05 May 2021 09:12:06 GMT</pubDate></item><item><title><![CDATA[Reply to Email Event Handler - support for multistate and binary values on Wed, 05 May 2021 08:05:55 GMT]]></title><description><![CDATA[<p dir="auto">In order to help you a little more here without confusing you in the process... Can you explain what you want to trigger the event and thus send the email?</p>
<p dir="auto">You can send an alert based upon value thresholds being crossed or no change in value or no updates for a period of time.</p>
<p dir="auto">If however you mean how you render the data, perhaps looking at writing a .ftl file will be a better port of call. Can show you how to assemble a model and map all affiliated values as desifed withba script...</p>
<p dir="auto">After that happy to walk you through the process.</p>
<p dir="auto">Fox</p>
]]></description><link>https://forum.mango-os.com/post/26608</link><guid isPermaLink="true">https://forum.mango-os.com/post/26608</guid><dc:creator><![CDATA[MattFox]]></dc:creator><pubDate>Wed, 05 May 2021 08:05:55 GMT</pubDate></item></channel></rss>