4 Replies Latest reply on Mar 15, 2017 7:31 AM by Ankit Gupta RSS
    flucciarini Newbie

    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

      • Re: How to change scheduler's configuration through script
        Ankit Gupta Ninja

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

            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)