Possible bug with Scripting data source editor
-
Hey guys,
I am using a scripting data source to prototype code for adding data points and I am encountering an annoying/challenging behaviour in the editor. It appears that when the script is loaded, all code after the "<" in the "for" condition is being chopped off.
For example, if I have the script:
I can create, save, and validate the script without issues. However, if I click to another data source and then return, all the code after the "<" is gone:
The same behaviour occurs even if the for loop is commented:
This behavior occurs both in Chrome and Firefox. I have also restarted the browser and server without any success.
If you need any further details, just let me know.
Thanks
IanEdit: I am not seeing any errors in the logs files or dev console.
Edit: where the "<" is in the code does not matter. If I add the character anywhere in the code, it gets chopped at that point:
PS: I don't see the log file being produced (or written) to if I have a log statement in the code:
The log file is not in the directory indicated. Perhaps there is a difference in logging if I validate/run the script versus it running automatically via the cron or context point.
-
Hi Ian,
I can assure you that the
<
sign can appear in scripts. It's a pretty common symbol! I was not able to readily reproduce...What version of Mango and the Scripting module are you using?
Perhaps there is a difference in logging if I validate/run the script versus it running automatically via the cron or context poin
Yes there is. It only actually logs to the file at runtime.
-
Hi Phil,
I am using the latest versions of Mango and the scripting modules (all the modules I have are the latest).
It's odd that you cannot reproduce as it seems to occur every time I work with the scripting data source editor. I will try to create a new data source and see if the issue occurs. I haven't seen the behaviour in any other script editor. I have worked around this for now by moving the code to a global script (and calling that function from the scripting data source).
Thanks for confirming when logging will occur.
Ian
-
Odd. Well, you could check the browser's developer tools. It should give some hint if it's hiding in the HTML or if some kind of JavaScript error occurred with displaying it. Perhaps export the data source and see if the saved script is intact?
-
Hi Phil,
I created another scripting data source in case the original source had been corrupted. Same behaviour:
When I look at the elements in dev tools for the editor, there is nothing beyond the "i" and the elements look properly formed. Nothing is being hidden; the markup looks proper.
Taking your suggestion, I exported the script and it appears that all the code is there:
{ "dataSources":[ { "xid":"DS_4eda2f4c-9c6b-4f43-ba77-ac4c44cdf9f9", "name":"Scripting Test 2", "enabled":false, "type":"SCRIPTING", "alarmLevels":{ "SCRIPT_ERROR":"URGENT", "DATA_TYPE_ERROR":"URGENT", "POLL_ABORTED":"URGENT", "LOG_ERROR":"URGENT" }, "purgeType":"YEARS", "updateEvent":"CONTEXT_UPDATE", "context":[ ], "logLevel":"NONE", "cronPattern":"0 * * * * ?", "executionDelaySeconds":0, "historicalSetting":false, "logCount":5, "logSize":1.0, "script":"\r\nvar mqttPoints = [\r\n {\r\n deviceName: \"TEST 10\",\r\n name: \"Buoy Id\",\r\n templateXid: \"MQTT_Value\",\r\n topic: \"buoyData\\\/10\",\r\n path: \"\\\/id\"\r\n }\r\n];\r\n\r\nvar dataSourceXid = \"DS_e71fa055-06f6-4e80-a1e8-b0b823378f3d\";\r\n\r\nfor (i=0; i<mqttPoints.length; i++) {\r\n LOG.info('Creating data point: '+mqttPoints*.name);\r\n createMQTTPoint(dataSourceXid, mqttPoints*);\r\n}\r\n\r\nfunction createMQTTPoint(dataSourceXid, values) {\r\n var dataPoint = mqttDataPointTmpl;\r\n \r\n var xidPrefix = \"DP_TEST_\";\r\n \r\n dataPoint.xid = com.serotonin.m2m2.Common.generateXid(xidPrefix);\r\n \r\n dataPoint.dataSourceXid = dataSourceXid;\r\n dataPoint.deviceName = values.deviceName;\r\n dataPoint.name = values.name;\r\n dataPoint.templateXid = values.templateXid;\r\n \r\n dataPoint.pointLocator.subscribeTopic = values.topic;\r\n dataPoint.pointLocator.subscribeJsonValuePath = values.path;\r\n\r\n JsonEmport.setImportDuringValidation(true);\r\n print(JsonEmport.doImportGetStatus(JSON.stringify( {\"dataPoints\":[dataPoint]} )));\r\n}\r\n\r\n", "scriptPermissions":{ "customPermissions":"", "dataPointReadPermissions":"superadmin", "dataPointSetPermissions":"superadmin", "dataSourcePermissions":"superadmin" }, "editPermission":"user", "purgeOverride":false, "purgePeriod":1 } ] }
So it's very odd that the editor is chopping the display of the code at the "<".
Thanks
Ian -
Okay. I was able to reproduce. I always put spaces after my
<
so somehow I've never crossed paths with this. Not sure if that's a new or old issue, but I'm looking into it. Thanks for bringing it to our attention and providing a failing case! -
Whew! Glad that you were able to reproduce it. heh
Edit: I see that having the space after the "<" prevents the chopping. Very odd... As I mentioned above, I have only seen this behaviour in the scripting data source editor.