• I
    iperry

    Hi Phil,

    I am hoping I am missing something very basic here. When I try to log the message string from evt, I still get an exception that the object is not defined.

    LOG.info(evt.getMessageString());

    return CANCEL;

    Failure: ReferenceError: "evt" is not defined in <eval> at line number 2 in <eval> at line number 2

    I had tried using evt before as I saw it being referenced in the ftl markup (and pop-up help) and appeared to be set to the model in EmailHandlerRT but had no success then.

    It appears that the evt object is available in the model (and thus the ftl) but not to the script.

    Thanks
    Ian

    posted in Scripting general Discussion read more
  • I
    iperry

    Hi Phil,

    I decided to use the data point id at this time as it was easy to use and meant I didn't need to construct my own unique id process. I tend to avoid using internal id values like that for external references but it works well enough for now.

    My process currently creates points for a "device" which includes 9 MQTT, 4 virtual and 12 meta points. I have created a basic template for each of the 3 types of points, which the process then populates based on the a list of points required. Works quite nicely.

    Now that I am trying to connect the process to email event handler (or set point handler) I am stuck with a simple problem: what is the correct event object? My handler script is:

    LOG.info('Unknown topic handler executed...');
    topicTest(event.getMessage());

    return CANCEL;

    Where topicTest is a global function that logs the message.

    If I validate the script, the log messages appear in the page.
    Success, email sending cancelled
    INFO 2019-03-12 14:55:11,950 - Unknown topic handler executed...
    INFO 2019-03-12 14:55:11,952 - Unknown topic received from MQTT server:Test

    When I trigger the handler for the first time, I get an error in the log that "event" is not defined. Any further triggers of the handler appear to be ok (the original warning message is logged).

    However, I only see the original warning in the ma.log file but not the 2 info messages. Is there something else I need to do?

    Thanks
    Ian

    posted in Scripting general Discussion read more
  • I
    iperry

    Hi Phil,

    I am circling back to this task and have been successful in creating MQTT and virtual data points. Creating meta data points doesn't seem to be that much different but I am stuck on how to set the var(iable) names for context points.

    I see that when I create meta points with context via the UI, the variable name will be automatically populated, such as "p500". How/where is this var name determined? When I create multiple meta points using the same data point in context, the same var name is used so I figured it must be maintained somewhere. However, I have yet been able to find the method that constructs it. I figure I could use my own var names but ideally I would like to use existing methods for creating/using these names for consistency.

    Any suggestions would be great.

    Thanks
    Ian

    posted in Scripting general Discussion read more
  • I
    iperry

    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.

    posted in User help read more
  • I
    iperry

    Hi Phil,

    I created another scripting data source in case the original source had been corrupted. Same behaviour:
    0_1551902655468_43ca932b-b9ab-4fa6-8b34-f4d1bb71d469-image.png

    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

    posted in User help read more
  • I
    iperry

    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

    posted in User help read more
  • I
    iperry

    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:
    0_1551893434890_7ec54e16-006c-4397-9ab1-e09ca8fbab1e-image.png

    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:
    0_1551893608176_04ed8cd7-5785-4545-9742-0c8754c6e36b-image.png

    The same behaviour occurs even if the for loop is commented:
    0_1551893796263_59da8c5c-9eb6-466a-b54a-68ea957cb99b-image.png

    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
    Ian

    Edit: 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:
    0_1551894920384_6f06dccd-4c06-4c4c-9c11-99fbf9d6b06c-image.png

    PS: I don't see the log file being produced (or written) to if I have a log statement in the code:
    0_1551895748294_1c63b29c-0c29-4961-96db-806133db0f73-image.png

    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.

    posted in User help read more
  • I
    iperry

    No worries. I had a brief moment of panic that my new markup wasn't working when I had copied from a "working" version. heh

    I look forward to the next release.

    posted in User help read more
  • I
    iperry

    Heya,

    I am circling back in my development to using Google Maps for displaying the location of remote sensors and finding a couple new errors with the library. I originally thought it was an issue with my code but when I viewed the dev tools for the maps example in Mango, the same errors are in the console.

    0_1550688000085_029cfd1e-adaf-4e7b-ac8b-6736d37fe103-image.png

    1. InvalidValueError: setIcon: not a string; and no url property; and no path property

    A search for this error seems to indicate there was a possible update to the Google Maps API.

    https://stackoverflow.com/questions/27290671/google-map-invalidvalueerror-seticon-not-a-string-and-no-url-property-and

    A link in the above Stackoverflow page to Google's issue tracker indicates that the latest version of the Markers with label library is needed. Maybe this is in the latest ng-maps?

    1. TypeError: Cannot read property 'parentElement' of null

    This error occurs when creating info-windows in ng-maps. The info-window works (sorta) but the first time you click on the marker, and empty window appears. When you close the window and click again, the proper behaviour occurs. According to the github link, the behaviour has been fixed in a latest ng-maps library.

    https://github.com/allenhwkim/angularjs-google-maps/issues/879

    Thanks
    Ian

    posted in User help read more
  • I
    iperry

    Awesome! Thanks Matt :)

    The part I was missing was using the subclass FileAttachment. doh

    All the parts work now. Once I get the code cleaned up, I will post it here.

    Need to make sure I bookmark the javadocs. I think I recall seeing them before but forgot all about them. heh

    Ian

    posted in User help read more