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

Community Tip - If community subscription notifications are filling up your inbox you can set up a daily digest and get all your notifications in a single email. X

How to change scheduler's configuration through script

flucciarini
4-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

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
ankigupta
5-Regular Member
(To:flucciarini)

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.

flucciarini
4-Participant
(To:ankigupta)

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)

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

ankigupta
5-Regular Member
(To:flucciarini)

Try using GetConfigurationTable.

Top Tags