Serverside script and var "events"
-
Hello,
I read on the online documentation about the available variables. It was not clearly documented how they can be used. made some tries like these.
var s=""; s += point.name; s += ": "; s += value; s += point.getTextRenderer().getSuffix(); s += " = "; s += renderedText; return s;
it prints out like this "Temperature: 21.375°C = 21,4°C"
Are these variables supposed to be used like this? :) It seems easiest to figure out the interfaces/methods on different objects by digging around the source codes. Would be great to have some list/tree/doc about the different objects.(maybe some html help/pages generated automatically from sources)
I have been thinking to make a small alarm panel on a graphical view, with selected events related to the view. I was looking for the event objects and trying to find out how I could get grab on the string which is printed on event list. Again diving into sources and ended up to this try and it does not work like supposed. And the next hop is missing :(
var s="" s +=events.get(0).message.key; return s;
(I found out by trying and the error messages gave hint the "events" is a list type of object) The message is object type of LocalizableMessage.
On the sources one essential file is missing and it seems to be used all around: "import com.serotonin.web.i18n.LocalizableMessage;"
Please tell where to find this?Any hints how to make the alarm list?
Thanks
-Jokke -
it prints out like this "Temperature: 21.375°C = 21,4°C"
Are these variables supposed to be used like this?
yes. A server side script can access only one point, its value, and properties.I have been thinking to make a small alarm panel on a graphical view, with selected events related to the view
As I know, it is currently not possible. "events" lists the pending event objects of the server side script's point.Regards,
Greg -
As I know, it is currently not possible. "events" lists the pending event objects of the server side script's point.
Yes it is only for the one point in case. But the issue is how to access the name/event string of it. The other properties needed from the event can be accessed. The type is EventInstance and in the source I found the public methods
e.g. like this
var s="" s +=events.get(0).getPrettyActiveTimestamp(); return s;
The point needs to have an active event to try. (This is just for testing. It is not vise to try accessing index 0, without first checking if the list has any values.)
I assume the name would be in the LocalizableMessage object but the source code is missing.
BR
-Jokke -
Hi Jokke,
Not sure what you mean by the "name". A LocalizableMessage is a (mostly) simple wrapper for a localization key (found in the translation files) and any parameters. It lives in the seroUtils.jar file, and so the source is not available.
It's most important method is getLocalizedMessage(ResourceBundle), which will return the string message in the language of the given resource bundle.
Does this information help?
-
hmmm,
Yes the information helps to understand.
I tried "events.get(0).message.getLocalizedMessage()"
and result was "Can't find method com.serotonin.web.i18n.LocalizableMessage.getLocalizedMessage()."
The name I refer is the defined alias for the point event detector. It is printed on event list as message.
I am not sure if trying to find it on correct object at all. Ill continue diving...
BR
-Jokke -
It can't find the method because the method takes a ResourceBundle parameter, so it looks for a method that takes no parameters, which doesn't exist.
I've added the appropriate resource bundle to the script context under the var "bundle". So, your script would be "events.get(0).message.getLocalizedMessage(bundle)". This will be available in the next release.
Do note though that the rendered events should appear in a warning rollover to the left of the component.