Assign dhtmlx scheduler firsthour and lasthour from database

I need some help to assign values to first_hour and last_hour to the scheduler. I get them working with hardcoding the values directly but couldnt get the way to assign the values i get from ajax call to the scheduler config. Please help.
Here is my code:

[code]Index.cshtml:
@Html.Raw(ViewBag.scheduler.GenerateLinks())

            scheduler.attachEvent("onTemplatesReady", function () {
               scheduler.date.decade_start = function (date) {
                var ndate = new Date(date.valueOf());
                ndate.setDate(Math.floor(date.getDate() / 10) * 10 + 1);
                return this.date_part(ndate);
            }
       
            $.ajax({
                type: "POST",
                url: window.location.pathname + "GS/GetTime",
                success: function (result) {
                    //alert("settimingcheck");
                    if (result != null) {
                        var s1 = result.split('|');
                        startime = s1[0];
                        endtime = s1[1];
                        alert(startime + endtime);
                     //   scheduler.config.first_hour = startime;
                      //  scheduler.config.last_hour = endtime;
                    }

                },
              
                error: function (xhr, status, error) {
                  
                    alert('Error settime');
                }
         
        });
          //code working with hardcode values 8 and 20
            scheduler.config.first_hour=8;
            scheduler.config.last_hou=12;
            scheduler.templates.decade_date = scheduler.templates.week_date;
            scheduler.templates.decade_scale_date = scheduler.templates.week_scale_date;
            scheduler.date.add_decade = function (date, inc) {
                return scheduler.date.add(date, inc * 30, "day");
            }
       
        });

    </script>

    @Html.Raw(ViewBag.scheduler.GenerateHTML())[/code]

Hello,
can you clarify where exactly the problem is?
As I see from your code, you retreive start/end values from the server success: function (result) { //alert("settimingcheck"); if (result != null) { var s1 = result.split('|'); startime = s1[0]; endtime = s1[1]; alert(startime + endtime); // scheduler.config.first_hour = startime; // scheduler.config.last_hour = endtime;
If they were retrieved correctly, you can update related configs (the commented lines) and redraw the scheduler to apply changes scheduler.setCurrentView();

I dont get them working when i assign them with values from database like this(commented lines after alert(startime + endtime);

[code]  scheduler.config.first_hour = startime;
  scheduler.config.last_hour = endtime;[/code]

i.e couldnt access scheduler inside ajaxcall, help pls

thankyou Aliaksandr, :slight_smile: that helped

It is working with the code below .But Scheduler loads a bit slow than if i assign it manually like this:

scheduler.config.first_hour = 09; scheduler.config.last_hour = 18;
Here is my working code:

[code]Index.cshtml:
@Html.Raw(ViewBag.scheduler.GenerateLinks())

scheduler.attachEvent(“onTemplatesReady”, function () {
scheduler.date.decade_start = function (date) {
var ndate = new Date(date.valueOf());
ndate.setDate(Math.floor(date.getDate() / 10) * 10 + 1);
return this.date_part(ndate);
}

            $.ajax({
                type: "POST",
                url: window.location.pathname + "GS/GetTime",
                success: function (result) {
                        if (result != null) {
                        var s1 = result.split('|');
                        startime = s1[0];
                        endtime = s1[1];
                        alert(startime + endtime);
                     scheduler.config.first_hour = startime;
                     scheduler.config.last_hour = endtime;
                     scheduler.setCurrentView();
                    }

                },
              
                error: function (xhr, status, error) {
                  
                    alert('Error settime');
                }
         
        });
                  
                 // scheduler.config.first_hour = 09;
                 // scheduler.config.last_hour = 18;
            scheduler.templates.decade_date = scheduler.templates.week_date;
            scheduler.templates.decade_scale_date = scheduler.templates.week_scale_date;
            scheduler.date.add_decade = function (date, inc) {
                return scheduler.date.add(date, inc * 30, "day");
            }
       
        });

    </script>

    @Html.Raw(ViewBag.scheduler.GenerateHTML())[/code]

i corrected it by using scheduler.updateView(); instead of scheduler.setcurrentview();