previousState in rules causes script error

I need to have the previous value of an Item in a rule that is triggered by an update. According to the documentation there should be an implicit variable previousState that is available in all rules that have an update trigger.
However if I use that variable it only get a script error in the log

22:26:33.885 [ERROR] [.script.engine.ScriptExecutionThread] - Rule ‘change_test’: An error occured during the script execution: index=0, size=0

This is the rule I used for testing:

rule change_test
when Item ScriptTest received update
then
	var oldvalue = previousState
end

does anyone has an idea?

Dominik

rule “change_test” perhaps?

IMHO you need a persistence service for the item setup and you need to call it like " MyItem. previousState"

Thanks! That did the trick.

rule change_test
when Item ScriptTest received update
then
	var oldvalue = ScriptTest.previousState().state
	logInfo ("change_test","oldvalue: " + oldvalue )
end

One additional comment: I still think that the documentation is wrong. As in the documentation it states that there is an implicit variable that could be accessed in any rule that was triggered by a change.

The documentation says previousState will be available in any rule triggered by change. Your rule is triggered by an update.

I’m surprised that doesn’t work too, but it does agree with the documentation.

Here’s an example of implicit previousState working for other people

Thanks a lot. This is working as well. I had overlooked the difference between the update and the change.