Saving to backend with multiple resources

Hi support,
I'm trying the schedule control with resources, but I have difficulties in saving the resources attached to an event. 
I have activated multiple resources.
The control is defined as:

var scheduleObj = new ej.schedule.Schedule({
width: '100%',
height: '700px',
rowAutoHeight: true,
allowDragAndDrop: false,
firstDayOfWeek: 1,
timezone: 'Europe/Berlin',
views: [{option: 'Month', interval: 6}],
selectedDate: new Date(2020, 0, 1),
resources: [{
field: 'resourceid', title: 'Resource',
name: 'Persongroups', allowMultiple: true,
dataSource: resourceData,
query: csrfQuery,
textField: 'Caption', idField: 'Id', colorField: 'Color'
}],
eventSettings: {
dataSource: calendarData,
query: csrfQuery,
template: '#apptemplate'
}
});
scheduleObj.appendTo('#Schedule');

With one resource selected, the request to the backend is:
{"changed":[{"Id":"1","Subject":"Test2","Location":"Berlin","StartTime":"2019-12-27T23:00:00.000Z","EndTime":"2020-01-03T23:00:00.000Z","IsAllDay":"0","Guid":"c8b7018d-8f58-89db-9a72-1dabef78b43a","StartTimezone":null,"EndTimezone":null,"resourceid":"5","RecurrenceRule":null}],"added":[],"deleted":[],"action":"batch","params":{"_csrf":"_FeDO2_ZE_a2JTi5taNkUKvwl121f0QCAoJDSjk7VBrOG-BVGYxjsP9xff39xxUg48XgL9AgCUBT1AI7ZgJjbg==","StartDate":"2019-12-29T23:00:00.000Z","EndDate":"2020-07-05T22:00:00.000Z"},"_csrf":"_FeDO2_ZE_a2JTi5taNkUKvwl121f0QCAoJDSjk7VBrOG-BVGYxjsP9xff39xxUg48XgL9AgCUBT1AI7ZgJjbg==","StartDate":"2019-12-29T23:00:00.000Z","EndDate":"2020-07-05T22:00:00.000Z"}

But if I add two resources, two requests are sent:
First:
{"changed":[{"Id":"1","Subject":"Test2","Location":"Berlin","StartTime":"2019-12-27T23:00:00.000Z","EndTime":"2020-01-03T23:00:00.000Z","IsAllDay":"0","Guid":"c8b7018d-8f58-89db-9a72-1dabef78b43a","StartTimezone":null,"EndTimezone":null,"resourceid":"3","RecurrenceRule":null}],"added":[],"deleted":[],"action":"batch","params":{"_csrf":"_FeDO2_ZE_a2JTi5taNkUKvwl121f0QCAoJDSjk7VBrOG-BVGYxjsP9xff39xxUg48XgL9AgCUBT1AI7ZgJjbg==","StartDate":"2019-12-29T23:00:00.000Z","EndDate":"2020-07-05T22:00:00.000Z"},"_csrf":"_FeDO2_ZE_a2JTi5taNkUKvwl121f0QCAoJDSjk7VBrOG-BVGYxjsP9xff39xxUg48XgL9AgCUBT1AI7ZgJjbg==","StartDate":"2019-12-29T23:00:00.000Z","EndDate":"2020-07-05T22:00:00.000Z"}

Second:
{"changed":[],"added":[{"Id":"1a3a7295-4859-9018-bb5c-29b10159b172","Subject":"Test2","Location":"Berlin","StartTime":"2019-12-27T23:00:00.000Z","EndTime":"2020-01-03T23:00:00.000Z","IsAllDay":"0","Guid":"c8b7018d-8f58-89db-9a72-1dabef78b43a","StartTimezone":null,"EndTimezone":null,"resourceid":"5","RecurrenceRule":null,"RecurrenceException":null,"RecurrenceID":null}],"deleted":[],"action":"batch","params":{"_csrf":"_FeDO2_ZE_a2JTi5taNkUKvwl121f0QCAoJDSjk7VBrOG-BVGYxjsP9xff39xxUg48XgL9AgCUBT1AI7ZgJjbg==","StartDate":"2019-12-29T23:00:00.000Z","EndDate":"2020-07-05T22:00:00.000Z"},"_csrf":"_FeDO2_ZE_a2JTi5taNkUKvwl121f0QCAoJDSjk7VBrOG-BVGYxjsP9xff39xxUg48XgL9AgCUBT1AI7ZgJjbg==","StartDate":"2019-12-29T23:00:00.000Z","EndDate":"2020-07-05T22:00:00.000Z"}

The second one is a very strange request.
Where does this Id come from? (1a3a7295-4859-9018-bb5c-29b10159b172)
I have no ids like this in my database, not in the events and not in the resources.
How can I select the event which I have to update, if I don't have an id?

And there is another thing:
It's a pity that the the control requires at least one resource (if the resource array is set in the configuration) otherwise the data is not sent.
But the user is not informed. The edit form closes but no request is sent.
And also the display is not correct. (a single click always shows a resource even if no one is attached).

I'm using the 18-2-48patch of ej2.

Regards,
Stephan

9 Replies 1 reply marked as answer

HB Hareesh Balasubramanian Syncfusion Team August 13, 2020 03:01 PM UTC

Hi Stephan, 

Greetings from Syncfusion Support..! 

We have validated your shared code snippets at our end. And we suspect that your requirement is to store the Scheduler events with multiple resources. And for that, we have prepared a CRUD sample, in that we have enabled the allowMultipe filed in the resources property and the same can be downloaded from the following link. 


Code snippet
var scheduleObj = new ej.schedule.Schedule({ 
  width: '100%', 
  height: '650px', 
  currentView: 'WorkWeek', 
  eventSettings: { dataSource: dataManger }, 
  group: { 
    allowGroupEdit: true, 
    resources: ['Conferences'] 
  }, 
  actionBegin: function (args) { 
    if (args.requestType == 'eventCreate' || args.requestType == 'eventChange') { 
      var event = !ej.base.isNullOrUndefined(args.data[0]) ? args.data[0] : args.data; 
      if (args.requestType == 'eventChange' && Object.keys(event)[0] == 'occurrence') { 
        event = event.occurrence; 
      } 
      // Before send the data to the db need to convert array into string 
      event['GroupID'] = event['GroupID'].toString(); 
    } 
  }, 
  dataBinding: function (args) { 
    var data = args.result; 
    var scheduleData = []; 
    data.forEach(function (element) { 
      var res = element.GroupID.split(','); 
      element.GroupID = res.map(function (x) { return parseInt(x, 10); }); 
      scheduleData.push(element); 
    }); 
    args.result = scheduleData; 
  }, 
  resources: [{ 
    field: 'GroupID', title: 'Attendees', 
    name: 'Conferences', allowMultiple: true
    dataSource: [ 
      { Text: 'Margaret', Id: 1, Color: '#1aaa55' }, 
      { Text: 'Robert', Id: 2, Color: '#357cd2' }, 
      { Text: 'Laura', Id: 3, Color: '#7fa900' } 
    ], 
    textField: 'Text', idField: 'Id', colorField: 'Color' 
  }] 
}); 

Note: Kindly maintain the Resource field as string type in the server-side. 

And for your reference, we have taken the below screenshot of the SchedulerEvents data image, 
 

And for further reference, kindly refer the below UG link, 

Kindly try the above CRUD sample and get back to us if you need any further assistance. 

Regards, 
Hareesh 



SS Stephan Schrade August 13, 2020 10:03 PM UTC

Hi support,
many thanks for your quick answer.

But sorry I just don't get it.
Why I do have to add so much JS code only to save multiple resources to an event?
In my example everything works perfect with 
creating an event
changing an event
deleting an event
adding one resource to an event.
So my backend any my JS code works.
But if I want to add multiple resources, I suddenly have to add so much code.

And I don't want to have a group view of my schedule, so I don't use the group property.

And by the way your code does not work.
Your stackblitz example does not work. I can't see any event.
And if I add your code snippet to my source, all my events are not displayed any more.

My response from the backend is:
[{
    "Id": "1",
    "Subject": "Test2",
    "Location": "Berlin",
    "StartTime": "2019-12-28 00:00:00",
    "EndTime": "2020-01-04 00:00:00",
    "IsAllDay": "0",
    "resourceid": [4]
}, {
    "Id": "2",
    "Subject": "Test2",
    "Location": "",
    "StartTime": "2020-01-07 23:00:00",
    "EndTime": "2020-01-08 23:00:00",
    "IsAllDay": "1"
}, {
    "Id": "3",
    "Subject": "Test3",
    "Location": "Berlin",
    "StartTime": "2020-01-08 00:00:00",
    "EndTime": "2020-01-09 00:00:00",
    "IsAllDay": "0"
}, {
    "Id": "5",
    "Subject": "Test5",
    "Location": "",
    "StartTime": "2020-01-20 00:00:00",
    "EndTime": "2020-01-23 00:00:00",
    "IsAllDay": "1"
}]

Please see also my other thread at 
https://www.syncfusion.com/forums/156859/oneclick-popup-shows-wrong-resource
where do I describe another strange behavior regarding resources.

Regards,
Stephan



HB Hareesh Balasubramanian Syncfusion Team August 14, 2020 05:11 PM UTC

Hi Stephan, 

Thanks for the update. 

We have validated your shared code snippets (data source for the Scheduler) at our end. And, we suspect that your requirement is to share a single event between the multiple resources like SharedEvent demo sample. And for that, we have modified our previously updated CRUD sample and it can be downloaded from the following link. 


Kindly try the above sample and If we misunderstand your requirement, kindly let us know more details about the use case scenario/video demo/image of your requirements for the better serve. 

Regards, 
Hareesh 



SS Stephan Schrade August 14, 2020 07:48 PM UTC

Hi support,
yes this is right, I need something like the SharedEvent. But with a view where I can see all the events in one calendar and not in three different ones.
I have about 10 resources and this would look very complicated to the user.
Is there no possibility to have all the events in one calendar and if click on the info I can see all the resources attached to this event?

Regards,
Stephan


HB Hareesh Balasubramanian Syncfusion Team August 17, 2020 01:04 PM UTC

Hi Stephan, 

Thanks for the update. 

We have validated your shared query “Is there no possibility to have all the events in one calendar and if click on the info I can see all the resources attached to this event?” at our end. And we suspect that you have removed the resources filed in the group property. And if we removed resource resources filed in the group property, then if we create an event for all the resources then we would able to render the single event for the entire selected resources and we are not able to add all those events in one calendar. And for the same, we have modified our previously updated sample and it can be downloaded from the following link. 


Code snippet
  group: { 
    allowGroupEdit: true, 
    // resources: ['Conferences'] 
  }, 

And for further reference, kindly refer the below UG link, 

Kindly try the above solution and If we misunderstand your requirement, kindly let us know more details about the use case scenario/video demo/image of your requirements for the better serve. 

Regards, 
Hareesh 



SS Stephan Schrade August 17, 2020 09:27 PM UTC

Hi support,
I'm sorry but this does not help. 

Perhaps I have to ask in another way:
Is there a type of schedule where I can attach multiple attendants to an event?
Like a meeting where I want to say that Luca, Marcus and Marcy are invited.
But still I don't want to have separate schedules with a schedule for each attendant.
I need this in one single schedule.
And I have noticed that when I change an event with two resources two events are created via the batch crud interface.
But this is not what I need.
Because then I'm always ending up in having two events. And if the meeting date changes, I have to change two events.
This makes things very complicated.
Why does the interface accept events with multiple resources at reading but not at updating?

Regards,
Stephan


HB Hareesh Balasubramanian Syncfusion Team August 18, 2020 01:55 PM UTC

Hi Stephan, 

Thanks for the update. 

We have validated both the queries at our end. And for that, we have prepared a sample and it can be viewed from the following link, 

Q1: But still I don't want to have separate schedules with a schedule for each attendant.I need this in one single schedule 

This query can be achieved by removing the resources field in the group property. And for further reference, kindly refer to the below code snippets. And the same can be viewed from the above sample. 

Code snippet: 
  group: { 
    allowGroupEdit: true, 
    resources: [] 
  }, 

And for further reference, kindly refer the below screenshot, 
 

Q2: Because then I'm always ending up in having two events. And if the meeting date changes, I have to change two events. This makes things very complicated. 
 
For this query, we suspect that you may not enable the allowGroupEdit filed in the group property, that could be the reason for the reported problem “two requests are passing while creating an event with multiple resources”. And for further reference, kindly refer to the below snippets and for that, we have prepared a sample with the local data source for the scheduler events. And the same can be viewed in the above sample. 
 
Code snippets: 
  group: { 
    allowGroupEdit: true, 
    resources: [] 
  }, 
 
Kindly try the above solution and kindly confirm your requirement to proceed further((i.e.,) need to implement the same with CRUD sample) at our end. 

Regards, 
Hareesh 


Marked as answer

SS Stephan Schrade August 19, 2020 02:20 AM UTC

Hi support,
thank you very much for your explanation.
Now everything works as expected and I'm happy :-)

Regards,
Stephan


VD Vinitha Devi Murugan Syncfusion Team August 19, 2020 11:07 AM UTC

Hi Stephan,

Thanks for the update.

We are glad that your requirement has fulfilled.

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

Regards,
M.Vinitha devi


Loader.
Up arrow icon