<?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[Calling JSON store item in scripting datasource]]></title><description><![CDATA[<p dir="auto">Dear community,</p>
<p dir="auto">Having not read through documentation I think it is more easier to ask in forums.</p>
<p dir="auto">Is it possible to call a JSON store item in a scripting datasource and modify it when needed?</p>
<p dir="auto">Example:</p>
<p dir="auto">Client modifies some data on front end in a JSON store and then starts a testing procedure. Testing procedure is handled by a scripting data source. When the script sees that the test is complete it should write test results into the JSON store object.</p>
<p dir="auto">Is this possible with m2m2 functions inside the scripting data source? Right now we have solved it to stop the test and that the client should then click end test button which sets the values but we would like it to be done automatically via scripting datasource.</p>
<p dir="auto">Maybe someone can point me to the right directions?</p>
<p dir="auto">Thanks,<br />
Thomas</p>
]]></description><link>https://forum.mango-os.com/topic/4495/calling-json-store-item-in-scripting-datasource</link><generator>RSS for Node</generator><lastBuildDate>Wed, 17 Jun 2026 04:06:37 GMT</lastBuildDate><atom:link href="https://forum.mango-os.com/topic/4495.rss" rel="self" type="application/rss+xml"/><pubDate>Thu, 26 Sep 2019 07:05:20 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Calling JSON store item in scripting datasource on Thu, 04 Mar 2021 08:49:45 GMT]]></title><description><![CDATA[<p dir="auto">Hi <a class="plugin-mentions-user plugin-mentions-a" href="/user/craigweb" aria-label="Profile: CraigWeb">@<bdi>CraigWeb</bdi></a> ,</p>
<p dir="auto">I was successful in following the suggestion and get access to JSON store in scripting data source. However, I cannot do the same in script area of Event Handler. I get the following error when trying to validate.</p>
<p dir="auto">java.lang.RuntimeException: java.lang.ClassNotFoundException: com.serotonin.m2m2.Common.getBean</p>
<p dir="auto">Any ideas?</p>
<p dir="auto">BR,<br />
Ricardo</p>
]]></description><link>https://forum.mango-os.com/post/26361</link><guid isPermaLink="true">https://forum.mango-os.com/post/26361</guid><dc:creator><![CDATA[ricardo]]></dc:creator><pubDate>Thu, 04 Mar 2021 08:49:45 GMT</pubDate></item><item><title><![CDATA[Reply to Calling JSON store item in scripting datasource on Thu, 26 Sep 2019 07:56:43 GMT]]></title><description><![CDATA[<p dir="auto">Hi <a class="plugin-mentions-user plugin-mentions-a" href="/user/craigweb" aria-label="Profile: CraigWeb">@<bdi>CraigWeb</bdi></a></p>
<p dir="auto">Thank you so much.</p>
<p dir="auto">Exactly what i needed !</p>
<p dir="auto">Thomas</p>
]]></description><link>https://forum.mango-os.com/post/23724</link><guid isPermaLink="true">https://forum.mango-os.com/post/23724</guid><dc:creator><![CDATA[ThomasEinasto]]></dc:creator><pubDate>Thu, 26 Sep 2019 07:56:43 GMT</pubDate></item><item><title><![CDATA[Reply to Calling JSON store item in scripting datasource on Thu, 26 Sep 2019 07:53:58 GMT]]></title><description><![CDATA[<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>
]]></description><link>https://forum.mango-os.com/post/23723</link><guid isPermaLink="true">https://forum.mango-os.com/post/23723</guid><dc:creator><![CDATA[CraigWeb]]></dc:creator><pubDate>Thu, 26 Sep 2019 07:53:58 GMT</pubDate></item></channel></rss>