Please Note This forum exists for community support for the Mango product family and the Radix IoT Platform. Although Radix IoT employees participate in this forum from time to time, there is no guarantee of a response to anything posted here, nor can Radix IoT, LLC guarantee the accuracy of any information expressed or conveyed. Specific project questions from customers with active support contracts are asked to send requests to support@radixiot.com.

Radix IoT Website Mango 3 Documentation Website Mango 4 Documentation Website

Creating model for use in Freemarker


  • Heya,

    I seem to be struggling with the syntax and layout of a model for use with Freemarker.

    The list of data points returned from DataPointQuery works as-is but if I try to create my own model, based on the data points list, I get the error: The value you try to list is an extended_hash (wrapper: f.t.SimpleHash), thus you must specify two loop variables after the "as"; one for the key, and another for the value, like <#... as k, v>).

    I want to create a model as I want to include information that isn't available in the records for each data point returned in the query.

    To me, this simple model appears similar to the data points but does not work:

    var tmpRecs = [
        {deviceName: 'PCU_110020', path: 'PCU_110090'},
        {deviceName: 'PCU_110021', path: 'PCU_110090'},
        {deviceName: 'PCU_110022', path: 'PCU_110090'}
    ];
    

    Most of the information I have found on the net is more Java related than specifically javascript.

    Does anyone have an example of a model in javascript they have built or some pointers as to what I am doing wrong? heh

    Any suggestions would be appreciated.

    Thanks
    Ian


  • I can probably help here. I use it to construct my data reports into an email.
    Javascript:

    var model = {"crit": crit, "urgent": urgent, "warn":warn};
    
    //print(JSON.stringify(model));
    var template = com.serotonin.m2m2.Common.freemarkerConfiguration.getTemplate("datapoint_email.ftl");
    
    var writer = new java.io.StringWriter();
    template.process(model, writer);
    var emailContent = new com.serotonin.web.mail.EmailContent(null, writer.toString(), com.serotonin.m2m2.Common.UTF8);
    
    var recipients = ["fox@domain.com"];
    com.serotonin.m2m2.rt.maint.work.EmailWorkItem.queueEmail(recipients, "Datapoint Summary", emailContent, null);
    

    Template

    <#assign key_list = crit?keys/> <!-- get keys -->
    <#list key_list as c> <!-- c is your array index -->
    <!-- markup fluff here -->
    <#list crit[c] as k,x> <!-- this point here would be your tmpRecs object -->
    <#assign row = row + 1/>
    	<#if row == 2><#assign row = 0/></#if>
    	<tr class="critrow<#if row == 1>Alt</#if>">
    	<td colspan="4">${x["id"]} </td> 
    	<td colspan="4"><span style="font-weight:bold">${x["deviceName"]}</span><span> : ${x["pointName"]}</span></td> 
    	<td colspan="4">${x["time"]} </td> 
    	<td colspan="4">${x["value"]} </td> 
    	</tr>
    <#else>
    <tr><td colspan="12">No Critical Items</td></tr>
    </#list>
    

    Would be good to see how you've laid out your model because that's what affects how the loop has to parse the data.

    Fox