Save item to persistance database

is it possible to save item in script ie call the persistence method from JS

Ideally I would like to save with a given date but can someone provide a short example how to persist and item. Note I will be calling this from rule.
thanks

Hi Paul,

Your question doesn’t make a great deal of sense, to me anyway.

To persist an item you’ll need to installed the relevant binding that covers your needs. An example being MapDB. For the persistence to work effectively you’ll need to configure the strategy that covers your requirements. Here’s a very basic configuration.

Strategies {
  default = everyUpdate
}

Items {
  * : strategy = everyChange, restoreOnStartup
}

I don’t know which is the correct call in JS, but in DSL Scripts it’s like that:

MyItem.persist

If you want to only persist from a script, you’ll have to ensure that an empty strategy is set:

Strategies {
  noAuto = "0 0 0 1 1 ? 1970" // only persist at 1.1.1970, 12:00 a.m.
  default = everyUpdate
}

Items {
  MyItem : strategy = noAuto
}

it looks like its like this in JS

items.getItem("Energy_Mains_Hourly").history.persist()
1 Like