Skip to main content
1-Visitor
March 15, 2017
Solved

How to change scheduler's configuration through script

  • March 15, 2017
  • 4 replies
  • 3754 views

Hi guys,

I want to change scheduler's configuration through a script called in a subscription event.

For scheduler entity find only DisableScheduler and EnableScheduler method.

Is it possible to change scheduler's configuration at "runtime"?

Thank's to all

    Best answer by flucciarini

    I find the problem

    correct code below

    var sch = Things["LightSwitchOn"];

    var params = {

      tableName: "Settings" /* STRING */

    };

    var ext = sch.GetConfigurationTable(params);

    var x = ext.getRow(0);

    x.SetStringValue("schedule", "0 " + cronDate.getMinutes() + " " + cronDate.getHours() + " * * ? *");

    x.SetBooleanValue("enabled", true);

    x.SetStringValue("runAsUser", "Administrator");

    var paramsSet = {

      configurationTable: ext /* INFOTABLE */,

      persistent: true /* BOOLEAN */,

      tableName: "Settings" /* STRING */

    };

    // no return

    sch.SetConfigurationTable(paramsSet);

    sch.EnableThing();

    logger.info("Controllo configurazione restart LightSwitchOn");

    sch.RestartThing();

    Thanks Ankit for java solution

    4 replies

    5-Regular Member
    March 15, 2017

    Hi Fabrizio Lucciarini​,

    We have option to set the Configuration by using the service SetConfigurationTable.

    After running the service you will have to call RestartThing Service to run it with the new configuration.

    I had written following Java Code to update the configuration sometime back. You can write a similar code in JavaScript.

    Thing sch = ThingUtilities.findThing("SchedulerXXX");

            InfoTable ext = sch.getConfigurationTable("Settings");

            ValueCollection x = ext.getRow(0);

           

            x.SetStringValue("schedule", "0/10 * * * * ? *");

            x.SetBooleanValue("enabled", true);

            x.SetStringValue("runAsUser", "Administrator");

           

           

            sch.SetConfigurationTable("Settings", ext, true);

           

            sch.EnableThing();

            sch.RestartThing();

    I hope it helps.

    1-Visitor
    March 15, 2017

    I write in javascript the code below

    var sch = Things["LightSwitchOn"];

    var ext = sch.getConfigurationTable("Settings");

    var x = ext.getRow(0);

    x.SetStringValue("schedule", "0 " + cronDate.getMinutes() + " " + cronDate.getHours() + " * * ? *");

    x.SetBooleanValue("enabled", true);

    x.SetStringValue("runAsUser", "Administrator");

    sch.SetConfigurationTable("Settings", ext, true);

    sch.EnableThing();

    sch.RestartThing();

    but I get the following error

    TypeError: Cannot find function getConfigurationTable in object com.thingworx.things.scheduler.SchedulerThing@36edb26b. (ScheduledEvent#18)

    flucciarini1-VisitorAuthorAnswer
    1-Visitor
    March 15, 2017

    I find the problem

    correct code below

    var sch = Things["LightSwitchOn"];

    var params = {

      tableName: "Settings" /* STRING */

    };

    var ext = sch.GetConfigurationTable(params);

    var x = ext.getRow(0);

    x.SetStringValue("schedule", "0 " + cronDate.getMinutes() + " " + cronDate.getHours() + " * * ? *");

    x.SetBooleanValue("enabled", true);

    x.SetStringValue("runAsUser", "Administrator");

    var paramsSet = {

      configurationTable: ext /* INFOTABLE */,

      persistent: true /* BOOLEAN */,

      tableName: "Settings" /* STRING */

    };

    // no return

    sch.SetConfigurationTable(paramsSet);

    sch.EnableThing();

    logger.info("Controllo configurazione restart LightSwitchOn");

    sch.RestartThing();

    Thanks Ankit for java solution