Id field

Hello, 

is there any case where Id of Event filed will be something other than null or UUID while creating new event?

I had some weird case, when on create event request had value of Id field equals to 1. 

KR, 
Ivan



12 Replies

BS Balasubramanian Sattanathan Syncfusion Team May 4, 2020 12:16 PM UTC

Hi Ivan, 

Greetings from Syncfusion Support. 

We have tried to validate your reported “is there any case where Id of Event filed will be something other than null or UUID while creating new event?” scenario at our side. But, we are unable to understand the requirement. So could you please share the below details to serve you better? 
  • Share the scheduler related code
  • Share the video demo or screenshot of your problem
  • Share a sample illustrating the problem which would help us to proceed further

Regards, 
Balasubramanian S 



IV Ivan May 4, 2020 06:59 PM UTC

Hello, 

in some cases ( about 2 times from 20 tries I can reproduce this problem ).



So, on actionBegin, if requestType is eventCreate I have custom method to call validation of event data on server side. Method only extracts data object based on action. 

actionBegin: function (args) {
if (args.requestType === 'eventCreate' && (args.data.length > 0 || !(new ej.base.isNullOrUndefined(args.data)))) {
   _setServicesData(false, args, args.data[0]);
   //args.data[0].Id = null;
   _validateCRUD(args, args.data[0], false);
}
_setServicesData is function that adds multiple services in event data field
record.Services = [];
record.Services.push(_service);
In some cases, within validate request, Id field is not null or doesn't contains UUID value, but value 1. 

This is not expected behaviour, because request is for create, and it cannot contain Id field with value. 

I manage that with setting Id manually to null when sending validate req ( see commented line in case of eventCreate - actionBegin).

validateCRUD sends entitiy via AJAX to server


It is pretty hard to reproduce problem!

KR;
Ivan


BS Balasubramanian Sattanathan Syncfusion Team May 5, 2020 01:55 PM UTC

Hi Ivan, 

Thanks for the update. 

We have validated the reported issue with your shared details and we suspect that your requirement is to set the null value to the Id field to the custom validation. While creating an event, the scheduler can generate the Id values and the same we can get in the actionBegin event. If we want the null value for the Id field we need to set as null by manually. 

Kindly set the Id field as null and check the result. If you still face the problem kindly share your custom validate code to serve you better. 

Regards, 
Balasubramanian S 



IV Ivan May 5, 2020 01:58 PM UTC

Hello, 


so this bellow is valid solution?

args.data[0].Id = null;

KR,
Ivan


VM Vengatesh Maniraj Syncfusion Team May 6, 2020 09:23 AM UTC

Hi Ivan, 

Yes, your solution is valid one. But once you completed the custom validation you need to restore its original value like below. 

var id = args.data[0].Id; 
args.data[0].Id = null; 
…….//custom validate function 
args.data[0].Id = id; 
 

Please check the above solution and get back to us for further assistance. 

Regards, 
Vengatesh 



IV Ivan replied to Vengatesh Maniraj May 6, 2020 09:26 AM UTC

Hi Ivan, 

Yes, your solution is valid one. But once you completed the custom validation you need to restore its original value like below. 

var id = args.data[0].Id; 
args.data[0].Id = null; 
…….//custom validate function 
args.data[0].Id = id; 
 

Please check the above solution and get back to us for further assistance. 

Regards, 
Vengatesh 


But then I have same problem while saving event. It's not common that new entity has ID ( except if this field is for offline mode ), Server has function to generate ID field


BS Balasubramanian Sattanathan Syncfusion Team May 7, 2020 02:14 PM UTC

Hi Ivan, 
 
Thanks for your update. 
 
Currently, we are validating your reported scenario at our side and will update further details on May 8, 2020. We would appreciate your valuable patience until then. 
 
Regards, 
Balasubramanian S


BS Balasubramanian Sattanathan Syncfusion Team May 11, 2020 10:59 AM UTC

Hi Ivan, 
 
Thanks for your valuable patience. 
 
We have validated your reported “I have same problem while saving event. It's not common that new entity has ID ( except if this field is for offline mode ), Server has function to generate ID field” problem at our side and prepared a sample based on that using DataManager like below code snippet. We let you know that, at the time of initial rendering of events the Url will trigger for fetching the events from the DB. If we perform CRUD actions (like create/edit/delete events) the CrudUrl will trigger for create/update the data(i.e., events) in the table of the DB and then the Url will trigger for fetching the updated events from DB to the client end. Kindly refer the below code snippets and follow it in your project.  
 
Front End : (index.js) 
var dataManger = new ej.data.DataManager({ 
  url: 'http://localhost:54738/Home/LoadData', // To get the initial data 
  crudUrl: 'http://localhost:54738/Home/UpdateData', // To store and get the data while perform the CRUD action 
  crossDomain: true, 
  adaptor: new ej.data.UrlAdaptor() 
}); 
 
Back End: (HomeController.cs) 
public class HomeController : Controller 
{ 
    ScheduleDataDataContext db = new ScheduleDataDataContext(); 
    public ActionResult Index() 
    { 
        return View(); 
    }         
    public JsonResult LoadData(Params param)  // Here we get the Start and End Date and based on that can filter the data and return to Scheduler 
    { 
        var data = db.ScheduleEventDatas.ToList();  // Here filtering the events based on the start and end date value. 
        return Json(data, JsonRequestBehavior.AllowGet); 
    } 
 
    public class Params 
    { 
        public DateTime StartDate { get; set; } 
        public DateTime EndDate { get; set; } 
    } 
 
    [HttpPost] 
    public JsonResult UpdateData(EditParams param) 
    { 
        if (param.action == "insert" || (param.action == "batch" && param.added != null)) // this block of code will execute while inserting the appointments 
        { 
            var value = (param.action == "insert") ? param.value : param.added[0]; 
            int intMax = db.ScheduleEventDatas.ToList().Count > 0 ? db.ScheduleEventDatas.ToList().Max(p => p.Id) : 1; 
            DateTime startTime = Convert.ToDateTime(value.StartTime); 
            DateTime endTime = Convert.ToDateTime(value.EndTime); 
            ScheduleEventData appointment = new ScheduleEventData() 
            { 
                Id = intMax + 1, // Id = intMax + 1, 
                StartTime = startTime, 
                EndTime = endTime, 
                Subject = value.Subject, 
                Location = value.Location, 
                Description = value.Description, 
                IsAllDay = value.IsAllDay, 
                StartTimezone = value.StartTimezone, 
                EndTimezone = value.EndTimezone, 
                RecurrenceRule = value.RecurrenceRule, 
                RecurrenceID = value.RecurrenceID, 
                RecurrenceException = value.RecurrenceException 
            }; 
            db.ScheduleEventDatas.InsertOnSubmit(appointment); 
            db.SubmitChanges(); 
        } 
        if (param.action == "update" || (param.action == "batch" && param.changed != null)) // this block of code will execute while updating the appointment 
        { 
            var value = (param.action == "update") ? param.value : param.changed[0]; 
            var filterData = db.ScheduleEventDatas.Where(c => c.Id == Convert.ToInt32(value.Id)); 
            if (filterData.Count() > 0) 
            { 
                DateTime startTime = Convert.ToDateTime(value.StartTime); 
                DateTime endTime = Convert.ToDateTime(value.EndTime); 
                ScheduleEventData appointment = db.ScheduleEventDatas.Single(A => A.Id == Convert.ToInt32(value.Id)); 
                appointment.StartTime = startTime; 
                appointment.EndTime = endTime; 
                appointment.StartTimezone = value.StartTimezone; 
                appointment.EndTimezone = value.EndTimezone; 
                appointment.Subject = value.Subject; 
                appointment.Location = value.Location; 
                appointment.Description = value.Description; 
                appointment.IsAllDay = value.IsAllDay; 
                appointment.RecurrenceRule = value.RecurrenceRule; 
                appointment.RecurrenceID = value.RecurrenceID; 
                appointment.RecurrenceException = value.RecurrenceException; 
            } 
            db.SubmitChanges(); 
        } 
        if (param.action == "remove" || (param.action == "batch" && param.deleted != null)) // this block of code will execute while removing the appointment 
        { 
            if (param.action == "remove") 
            { 
                int key = Convert.ToInt32(param.key); 
                ScheduleEventData appointment = db.ScheduleEventDatas.Where(c => c.Id == key).FirstOrDefault(); 
                if (appointment != null) db.ScheduleEventDatas.DeleteOnSubmit(appointment); 
            } 
            else 
            { 
                foreach (var apps in param.deleted) 
                { 
                    ScheduleEventData appointment = db.ScheduleEventDatas.Where(c => c.Id == apps.Id).FirstOrDefault(); 
                    if (apps != null) db.ScheduleEventDatas.DeleteOnSubmit(appointment); 
                } 
            } 
            db.SubmitChanges(); 
        } 
        var data = db.ScheduleEventDatas.ToList(); 
        return Json(data, JsonRequestBehavior.AllowGet); 
    } 
 
    public class EditParams 
    { 
        public string key { get; set; } 
        public string action { get; set; } 
        public List<ScheduleEventData> added { get; set; } 
        public List<ScheduleEventData> changed { get; set; } 
        public List<ScheduleEventData> deleted { get; set; } 
        public ScheduleEventData value { get; set; } 
    } 
} 
 
 
Note: Please run the service application before checking the sample. 
 
Kindly try the above sample and let us know if you need further assistance. 
 
Regards, 
Balasubramanian S


IV Ivan May 14, 2020 06:22 AM UTC

hello, 

sorry for late response.

In a backend I use Spring Boot and Java. 

I think I should update my validator in a way that I don't use resource.getId() != null || resource.getId() != uuid format. I will switch to Your logic

 if (param.action == "update" || (param.action == "batch" && param.changed != null))

And I think, that will everything be ok.

KR,
Ivan


VM Vengatesh Maniraj Syncfusion Team May 15, 2020 04:55 AM UTC

Hi Ivan, 

Thanks for the update. 

Kindly try out with our logic and if you still face any problem, please share your backend source(service project) to serve you better.  

Regards, 
Vengatesh 



IV Ivan May 19, 2020 06:38 AM UTC

Hello,

this is ok now. I changed my logic on server side and everything works as expected!

It's interesting how component generate 2 type of values for id ( uuid and number ). 


Thanks for amazing support!


VM Vengatesh Maniraj Syncfusion Team May 20, 2020 08:36 AM UTC

Hi Ivan, 

You are most welcome. 

Please get in touch with us if you need any further assistance. 

Regards, 
Vengatesh 


Loader.
Up arrow icon