Community Tip - Learn all about the Community Ranking System, a fun gamification element of the PTC Community. X
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
Solved! Go to Solution.
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
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.
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
Try using GetConfigurationTable.