cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

How to change scheduler's configuration through script

SOLVED
flucciarini
Participant

How to change scheduler's configuration through script

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

1 ACCEPTED SOLUTION

Accepted Solutions

Re: How to change scheduler's configuration through script

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

View solution in original post

4 REPLIES 4

Re: How to change scheduler's configuration through script

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.

Re: How to change scheduler's configuration through script

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)

Re: How to change scheduler's configuration through script

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

View solution in original post

Re: How to change scheduler's configuration through script

Try using GetConfigurationTable.

Announcements

Check out the upcoming Expert Session: Understanding ThingWorx Navigate Licensing in Community "Customer Events" section.