Adding custom field while inserting appointment

Hello there, I currently have the following Model to be used for my Schedule control.

public class ELLAssessmentBooking
    {
        public int Id { get; set; }
        public string Subject { get; set; }
        public string Description { get; set; }
        public DateTime StartTime { get; set; }
        public DateTime EndTime { get; set; }
        public string Categorize { get; set; }
        public string Location { get; set; }
        public int RegistrationID { get; set; }
        public int OwnerId { get; set; }
        public bool AllDay { get; set; }
        public bool Recurrence { get; set; }
        public string RecurrenceRule { get; set; }
    }

Please note that "RegistrationID" variable is a custom variable that I added.

Now, Here's how my Schedule looks like in the front end.

.AppointmentSettings(fields => fields.Datasource(datasource => datasource.URL("/ELLCalendar/GetAppointmentsAsync").BatchURL("/ELLCalendar/Crud").InsertURL("/ELLCalendar/Add").Adaptor(AdaptorType.UrlAdaptor))
                    .ApplyTimeOffset(false)
                    .Id("Id")
                    .Subject("Subject")
                    .StartTime("StartTime")
                    .EndTime("EndTime")
                    .Description("Description")
                    .Location("Location")
                    .Categorize("Categorize")                 
                    )

Is there a way to pass RegistrationID when adding an appointment? It is always nothing (or 0 int) when I am executing "Add" Action at the moment.



RegistrationID passed onto the page when it loads from the first time using a Query string and a "Get" event.(e.g. http://something/controlname?Registration=1234)

How can I populate this RegistrationID when I am saving?



5 Replies

NR Nevitha Ravi Syncfusion Team October 17, 2017 12:34 PM UTC

Hi Andrew, 

Thank you for contacting Syncfusion support. 

We have prepared the CRUD sample to save the appointment with custom field which can be downloaded from the below location. 


<Code> 
function onBeforeAppointmentCreate(args) { 
       if (!ej.isNullOrUndefined(args.appointment[0])) 
          args.appointment[0]["RegisterId"] = this._appointmentAddWindow.find('.RegisterId').val(); 
   } 
</Code> 

 

Now, the appointment is saved with the custom field (as highlighted) value in the DB as shown above.  
  
Regards, 
Nevitha


AJ Andrew Jang October 17, 2017 08:53 PM UTC

Thank you for your reply. I had to tweak a little to make it work, but it still works.

I have an additional question related to this.

I've modified your javascript function as follows.


<script>

    function onAppointmentOpen(args) {

    if (this._appointmentAddWindow.find(".custom-fields").length == 0) {

        var customDesign = "<tr class='custom-fields'><td class='e-textlabel'>Registeration ID</td><td><input class='RegistrationID' type='text' /></td></tr>";

        $(customDesign).insertAfter(this._appointmentAddWindow.find("#" + this._id + "subject"));

    }


    if (!ej.isNullOrUndefined(args.appointment)) {

        this._appointmentAddWindow.find(".RegistrationID").val(args.appointment.RegistrationID);

    } else {

        this._appointmentAddWindow.find(".RegistrationID").val(getParameterByName('RegistrationID'));

    }


    this._appointmentAddWindow.find(".subject").val('@ViewBag.Name');

}

</script>


As you see here, I am trying to pre-populate "Subject" with ViewBag.Name. However, when I open appointmentWindow, Subject field is always empty.



I would like to apply at least one of the following three to the subject field.

1. Pre-populate Subject field when the window opens.

2. Hide Subject field and it's label upon opening the window.

3. Pre-populate subject field AND ReadOnly (ideal case).


Thank you



NR Nevitha Ravi Syncfusion Team October 18, 2017 12:38 PM UTC

Hi Andrew, 

Thanks for your update. 

We have modified the sample to hide the subject field in the default appointment window as per your requirement which can be downloaded from the below location. 

Kindly refer the below code for your reference. 

<Code> 
function onAppointmentOpen(args) { 
        if (this._appointmentAddWindow.find(".custom-fields").length == 0) { 
           var customDesign = "<tr class='custom-fields'><td class='e-textlabel'>Register ID</td><td><input class='RegisterId' type='text' /></td></tr>"; 
           $(customDesign).insertAfter(this._appointmentAddWindow.find("#" + this._id + "subjecttr")); 
           this._appointmentAddWindow.find("#" + this._id + "subjecttr").css("display", "none");  // to hide the Subject field 
        } 
 
           if (!ej.isNullOrUndefined(args.appointment)) { 
             this._appointmentAddWindow.find(".RegisterId").val(args.appointment.RegisterId); 
           } else { 
               this._appointmentAddWindow.find(".RegisterId").val(""); 
           } 
   } 
   function onBeforeAppointmentCreate(args) { 
       if (!ej.isNullOrUndefined(args.appointment[0])) 
          args.appointment[0]["RegisterId"] = this._appointmentAddWindow.find('.RegisterId').val(); 
   }    
</Code> 

Regards, 
Nevitha 



AJ Andrew Jang October 18, 2017 09:20 PM UTC

Thank you, it is working now!



NR Nevitha Ravi Syncfusion Team October 19, 2017 03:58 AM UTC

Hi Andrew, 

We are happy that our solution fulfilled your requirement. Kindly let us know if you need any assistance.  

Regards, 
Nevitha. 


Loader.
Up arrow icon