logo

Monitoring history of object instance changes with scripts

You can use EntityActionHistoryManager to get the history of object changes. In its parameters, you need to pass the object instance, which you want to monitor. Say, we have a Test object and we want to monitor the history of changes in its first instance.

//obtain the first instance of the Test object, that is the isntance with ID 1
//you can choose a different way to obtain an object item
var e = EntityManager<Test, long>.Instance.LoadOrNull(1);
//if the instance is found then
if (e != null)
{
  //load its history to the hist variable
  var hist = EntityActionHistoryManager.Instance.LoadHistory(e).ToList();
  //show information about changes in console:
  //old value, new value, changed on
  //you can write these values to other variables insted of displaying them in console
  hist.ForEach(h =>{
                Console.WriteLine("--------------------------------");
            Console.WriteLine(((Test)h.Old).Tekst);
            Console.WriteLine(((Test)h.New).Tekst);
            Console.WriteLine(h.ActionDate.ToString());                         
               });
}

For the script to work correctly you need the following namespaces:

using EleWise.ELMA.ConfigurationModel;
using EleWise.ELMA.Common.Managers;
using EleWise.ELMA.Model.Managers;
You need to set the Old and New properties of the history to the object type in order to have access to properties of the object other than just the name field.

For the history to be available and for the script to work go to the object settings and in the Program Settings section of the Advanced tab check the "Store history" box.