Skip to content

Synchronizing logs

Introduction

Automatic synchronization of logs from controllers is normally made once every night. You can, however, initiate a synchronization at any time by executing some EXObasic.
In this excercise we will do just that using the Legacy context object.

Note

The complete view can be downloaded from here, but you will still need to follow some of the setup steps for it to work.

Setup

  • In SSF_Tutorials, create a new User Area called Synchronize.
  • Open Folder Views Tool and remove all the default Widgets and Link Icons.
  • Create a new Link Icon and leave the default name as is (UnnamedLinkIcon_1).
    • Change the (Global) Controller argument to a controller that exists in your project

In the File attribute, select Create a new view in this user area..., change the name to SynchronizeLogs.Rwav and save the the changes in Folder Views Tool.

Open the newly created view for editing.

  • Remove the default elements.
  • Add a Button with the name Synchronize.
  • Add a Text element with the name Result.
  • Save the file.

In your browser, navigate to the new User Area and make sure the elements display correctly.

Adding the server-side code

In the view root object, on the Javascript tab, open up the ServerSideJS editor and paste the following code:

ServerSideJS
return {
  synchronize: async (args, callInfo) => {
    // Macros work fine in ServerSide code
    return await callInfo.context.legacy.execute('%Controller%.Synchronize');
  }
}

Adding the client-side code

Open the OnManeuver editor for the Button and paste the following code. Make sure to save the view when done:

OnManeuver
this.view.call('.synchronize', { }).then((result) => {
  // result.executedOk returns true/false
  this.view.Result.value(result.executedOk);
});

The result

Open your browser and navigate to the area. When your view loads it should look like this:

Not synchronized yet

Click Synchronize and wait a couple of seconds. If all goes well you should get the following result:

Synchronized

Quick review

In this part we initiated a synchronization of logs from a controller using the Legacy context object. The name of the controller was passed in to the view as an argument, and we used a macro in the ServerSide code.

Ideas and improvements

You can execute any EXObasic code using this method so your imagination is the only limit here. Check out the EXObasic reference (in the EXOscada help) for inspiration.