Hi,
After an assignment change the tool starts to make multiple calls, can you please let us know what is the expected response by the tool.
Hi,
Could you please provide the steps to reproduce it? Are you able to reproduce it in our online example here : https://bryntum.com/examples/scheduler-pro/ ?
Hi,
We are not able to reproduce it in the online examples. Following is the configuration of auto sync
const project = (window.project = new ProjectModel({
eventStore: {
syncDataOnLoad: true,
fields: [{ name: 'dirtyCounter', type: 'number' }],
modelClass: TrainEventModel
},
transport: {
load: {
url: '/api/train-schedule'
},
sync: {
url: '/api/sync-events',
method: 'post'
}
},
autoLoad: true,
autoSync: true,
delayCalculation: false
}))
This issue is happening when ever user makes the assignment change of an event from one resource to other
From the backend we are sending back the request that we get along with the some extra parameter i've attached a response
{
"type": "sync",
"requestId": 1656408924330616,
"events": {
"updated": [{
"startDate": "2022-06-01T15:35:00+05:30",
"endDate": "2022-06-01T17:15:00+05:30",
"constraintDate": "2022-06-01T15:35:00+05:30",
"id": 3
}]
},
"assignments": {
"added": [{
"units": 100,
"resourceId": 3,
"eventId": 3,
"ID": 3,
"$PhantomId": "_generatedQ3690"
}]
},
"resp": [{
"OutputParameters": [],
"ReturnCode": 0,
"ResultSets": {
"Table1": []
}
}, {
"OutputParameters": [],
"ReturnCode": 0,
"ResultSets": {
"Table1": []
}
}]
}
Hi,
It is not a typo, this is the exact request that is being sent from the schedular after the change. I've attached the request and response both, please take a look
Request
,
{
"type": "sync",
"requestId": 16564956254421,
"assignments": {
"added": [{
"units": 100,
"resourceId": 5,
"eventId": 2,
"ID": 2,
"$PhantomId": "_generatedQ4"
}]
}
}
Response
{
"type": "sync",
"requestId": 16564956254421,
"assignments": {
"added": [{
"units": 100,
"resourceId": 5,
"eventId": 2,
"ID": 2,
"$PhantomId": "_generatedQ4"
}]
},
"resp": [{
"OutputParameters": [],
"ReturnCode": 0,
"ResultSets": {
"Table1": []
}
}]
}
We are just looking for the expected response from the sync API by the tool. Can you please share a format of response required by the tool for every change that happens on the tool
Hi,
You said you have multiple requests after adding assignment, since it's hard to reproduce without test case and backend, I asked for all requests for this operation - first sync (with steps what exactly was done - drag-n-drop or something else), server response, second sync, second server response, etc.
For now what I see, you used wrong name for id
field. You used id
for events, but ID
for assignments. I don't see you specified https://www.bryntum.com/docs/scheduler-pro/api/Core/data/Model#property-idField-static or data mapping in ProjectModel configs to use ID
as idField for AssignmentModel.
Try to use id
for assignments, if didn't help, please provide clear steps to reproduce and full stack of responses/requests, it will help us to find what exactly has not been saved after first sync and why second sync has been called.
Regarding to response format, try to enable https://www.bryntum.com/docs/scheduler-pro/api/Scheduler/crud/mixin/AbstractCrudManagerValidation#config-validateResponse to see warnings about data format in the console.
Example:
const project = new ProjectModel({
transport : {
load : {
url : 'data/data.json'
}
},
autoLoad : true,
// This config enables response validation and dumping of found errors to the browser console.
// It's meant to be used as a development stage helper only so please set it to false for production systems.
validateResponse : true
});
All the best,
Alex
Hi Alex, let me try and rephrase the problem we are seeing.
We have the following configuration snippet working for all sync activities except for moving events between resources:
eventStore: {
syncDataOnLoad: true,
fields: [{ name: 'dirtyCounter', type: 'number' }],
modelClass: TrainEventModel
},
transport: {
load: {
url: '/api/train-schedule'
},
sync: {
url: '/api/sync-events',
method: 'post'
}
},
autoLoad: true,
autoSync: true,
delayCalculation: false
When Surjit says we have multiple requests what he means is that when we drag and drop an event between resources it triggers multiple sync events that we can see in dev tools. They are all the same except for it generates a new requestID. This screenshot is after I have moved one event to another line/resource grouping.
They all have the following payload:
{type: "sync", requestId: 16566021486551,…}
assignments: {
added: [{units: 100, resourceId: 2, eventId: 1, ID: 1, $PhantomId: "_generatedClassDefEx3"}]
}
added: [{units: 100, resourceId: 2, eventId: 1, ID: 1, $PhantomId: "_generatedClassDefEx3"}]
0: {units: 100, resourceId: 2, eventId: 1, ID: 1, $PhantomId: "_generatedClassDefEx3"}
$PhantomId: "_generatedClassDefEx3"
ID: 1
eventId: 1
resourceId: 2
units: 100
requestId: 16566021486551
type: "sync"
We do not have anything using ID in capital letters. We believe this is generated by Scheduler. The call above is the call to our Node server api which I have pasted here (I have removed some irrelevant code) :
router.post('/sync-events', async (req, res) => {
const request = req.body;
const { events, dependencies, assignments } = request;
const resp = [];
if (events) {
const update = events.updated;
for (let event of update) {
const eventRequest = [
{
name: 'EventID',
value: event.id,
dataType: 'int'
},
{
name: 'LastUpdatedBy',
value: 'v-surjkumar',
dataType: 'varchar'
},
{
name: 'FMETaskID',
value: 2,
dataType: 'int'
}
];
const eventRecord = await getRequest(event);
console.log(eventRecord);
if (!eventRecord) {
continue;
}
console.log(eventRequest);
const result = await callSP('TrainSchedule_Events_UpdateData', eventRequest)
resp.push(result)
}
}
if (assignments) {
const { added } = assignments;
for (let assignment of added) {
const params = [
{
name: 'EventID',
value: assignment.eventId,
dataType: 'int'
},
{
name: 'ResourceID',
value: assignment.resourceId,
dataType: 'int'
}
]
const result = await callSP('TrainSchedule_Assignment_UpdateData', params)
resp.push(result)
}
}
if (dependencies && dependencies?.added) {
const { added } = dependencies;
for (let event of added) {
const params = [
{
name: 'EventID',
value: event.from,
dataType: 'int'
},
{
name: 'DependentEventID',
value: event.to,
dataType: 'int'
},
{
name: 'EventTypeID',
value: 2,
dataType: 'int'
},
]
const result = await callSP('TrainSchedule_Dependencies_UpdateData', params)
resp.push(result)
}
}
return res.json({...req.body, resp});
})
We do not doubt that it is possible that we are returning the wrong response back but Surjit's question is, "What should the response back look like?"
After adding the validateResponse: true we see this:
- "assignments" store "rows" section should mention added record(s) #_generatedClassDefEx12 sent in the request. It should contain the added records identifiers (both phantom and "real" ones assigned by the backend).
Please adjust your response to look like this:
{
"assignments": {
"rows": [
{
"$PhantomId": "_generatedClassDefEx12",
"id": ...
}
]
}
}
Does this mean that we need to rewrite the standard response sent from Scheduler to conform to this format?