<?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[Writting to JSON store from a Global Script]]></title><description><![CDATA[<p dir="auto">Hi everyone. New to Mango so bare with me.<br />
I'm trying to figure out how to write data to the JSON store from a global script.<br />
The intent is to pass some variables to a global script, have it massage that data and write some JSON to the JSON store.</p>
<p dir="auto">If someone could point me toward a document describing how to access the JSON store from a script. Thanks so much</p>
]]></description><link>https://forum.mango-os.com/topic/5132/writting-to-json-store-from-a-global-script</link><generator>RSS for Node</generator><lastBuildDate>Sat, 11 Apr 2026 15:04:17 GMT</lastBuildDate><atom:link href="https://forum.mango-os.com/topic/5132.rss" rel="self" type="application/rss+xml"/><pubDate>Tue, 23 Mar 2021 18:05:09 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Writting to JSON store from a Global Script on Wed, 07 Apr 2021 16:25:21 GMT]]></title><description><![CDATA[<p dir="auto">Can you show your whole method instead of the error? Cant really help otherwise. Also version of Mango would also be helpful to know as 4.x has some major changes in scripting env.</p>
]]></description><link>https://forum.mango-os.com/post/26507</link><guid isPermaLink="true">https://forum.mango-os.com/post/26507</guid><dc:creator><![CDATA[ThomasEinasto]]></dc:creator><pubDate>Wed, 07 Apr 2021 16:25:21 GMT</pubDate></item><item><title><![CDATA[Reply to Writting to JSON store from a Global Script on Tue, 06 Apr 2021 18:45:08 GMT]]></title><description><![CDATA[<p dir="auto">Hello<br />
I am getting an error with this script</p>
<pre><code>"com.serotonin.m2m2.rt.script.ScriptError: TypeError: dao.save is not a function at line: 49"
</code></pre>
<p dir="auto">dao is defined above as</p>
<pre><code>var dao = com.serotonin.m2m2.db.dao.JsonDataDao.instance;
</code></pre>
]]></description><link>https://forum.mango-os.com/post/26501</link><guid isPermaLink="true">https://forum.mango-os.com/post/26501</guid><dc:creator><![CDATA[marganellim]]></dc:creator><pubDate>Tue, 06 Apr 2021 18:45:08 GMT</pubDate></item><item><title><![CDATA[Reply to Writting to JSON store from a Global Script on Fri, 02 Apr 2021 07:51:51 GMT]]></title><description><![CDATA[<p dir="auto">Dao and serotonin stuff are Mango backend in Java. As Scripting in Mango allows users to write either in Java or Javascript you are able to initiate backend functions also easily. This in return allows users to search around IAS Github but without documentation. e.g. you can get points and set them also using Java methods if you know how to access them instead of adding points to context in the DS.</p>
]]></description><link>https://forum.mango-os.com/post/26483</link><guid isPermaLink="true">https://forum.mango-os.com/post/26483</guid><dc:creator><![CDATA[ThomasEinasto]]></dc:creator><pubDate>Fri, 02 Apr 2021 07:51:51 GMT</pubDate></item><item><title><![CDATA[Reply to Writting to JSON store from a Global Script on Thu, 01 Apr 2021 06:00:29 GMT]]></title><description><![CDATA[<p dir="auto">Sorry, I did dig up this post but was confused by the data access object and serotonin stuff. I assumed this was some sort of special case.<br />
I will experiment with this more and in future be a bit more thorough in my searching.<br />
Thanks</p>
]]></description><link>https://forum.mango-os.com/post/26475</link><guid isPermaLink="true">https://forum.mango-os.com/post/26475</guid><dc:creator><![CDATA[marganellim]]></dc:creator><pubDate>Thu, 01 Apr 2021 06:00:29 GMT</pubDate></item><item><title><![CDATA[Reply to Writting to JSON store from a Global Script on Sat, 27 Mar 2021 10:51:04 GMT]]></title><description><![CDATA[<p dir="auto">Hi</p>
<p dir="auto">I would suggest searching the forums first. There is a thread for that and an answer by <a class="plugin-mentions-user plugin-mentions-a" href="/user/craigweb" aria-label="Profile: CraigWeb">@<bdi>CraigWeb</bdi></a></p>
<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/craigweb" aria-label="Profile: craigweb">@<bdi>craigweb</bdi></a> said in <a href="/post/23723">Calling JSON store item in scripting datasource</a>:</p>
<blockquote>
<p dir="auto">Hi <a class="plugin-mentions-user plugin-mentions-a" href="/user/thomaseinasto" aria-label="Profile: ThomasEinasto">@<bdi>ThomasEinasto</bdi></a></p>
<p dir="auto">Here is some extracts of a scripting data source I did recently minus the logic I did on the JSON.</p>
<pre><code>var dao = com.serotonin.m2m2.db.dao.JsonDataDao.instance;
var objectMapper = com.serotonin.m2m2.Common.getBean(com.fasterxml.jackson.databind.ObjectMapper.class, "daoObjectMapper");

var jsonDataVo = dao.getByXid('8b203a82-166a-4963-8dc5-17bba149e28b');
var dataAsString = jsonDataVo.jsonData.toString();
var data = JSON.parse(dataAsString);
</code></pre>
<p dir="auto">You can now edit the <strong>data</strong> object as you would normally in JS</p>
<pre><code>  var newJsonData = objectMapper.readTree(JSON.stringify(data)); 
 //If objectmapper is not used before saving, all objects get saved as an array.
  jsonDataVo.setJsonData(newJsonData); 
  dao.save(jsonDataVo) 
</code></pre>
<p dir="auto">To save back to the JSON store.</p>
</blockquote>
]]></description><link>https://forum.mango-os.com/post/26440</link><guid isPermaLink="true">https://forum.mango-os.com/post/26440</guid><dc:creator><![CDATA[ThomasEinasto]]></dc:creator><pubDate>Sat, 27 Mar 2021 10:51:04 GMT</pubDate></item></channel></rss>