Avatar

DriverChange not always working

0

Hello, 

             I did a lot of tests to do some DriverChange  in C# and JS and the majority of the time, it is not working at all, even if it is giving me the ID for confirmation.

            In Js, I tried like that:

api.call("Add", {"typeName":"DriverChange",

"entity":{
"device":{"id":"b6C"},
"driver":{"id":"b6"},
"type":"Driver",
"dateTime": new Date().toISOString()
}
});

I checked the forum and the documentation... and I really don't know if I missed something at this point...

 

Thanks for help, I am clueless.

 

Patrick Begin

Please sign in to leave a comment.

7 comments

0
Avatar

Hi,

First of all, you can only specify either a device search OR a user search. 

Second, the correct notation for searching by driver is "UserSearch", and "DeviceSearch" for searching by device.You can also specify a date range for the search using "fromDate" and "toDate"

Please see sample script below:

api.call("Get", {
"typeName": "DriverChange",
"search": {
//"DeviceSearch": {"id":"b71"},
"UserSearch":{"id":"b4C"},
"fromDate":"2018-12-01T00:00:00.000Z",
"toDate":"2018-12-06T05:00:00.000Z"
}
}, function(result) {
console.log("Done: ", result);
}, function(e) {
console.error("Failed:", e);
});

Christoph Middleton 0 votes
0
Avatar

Hi Christoph, 

          thanks for the answer, but I think there is a misunderstanding in your answer:

        I don't want to do a "GET".. but an "ADD".

        But thanks for the sample for a "GET" for the "DriverChange".

Patrick Begin 0 votes
0
Avatar

I think I find the right way to do it because of the sample you give me Christoph. Thanks again.

To help other people in the next years with the same problem 

api.call("Add", {"typeName":"DriverChange",
         "entity":{
                   "device":{"id":"a123"},
                   "driver":{"id":"b123"},
                   "type":"Driver",
                   "dateTime": "2018-12-07T01:13:43.000Z" //<= this is the right way to put the datetime
          }
});

Patrick Begin 0 votes
0
Avatar

Hi,

Sorry about the confusion on my previous comment. I tested both your sample calls and they both appear to work. The "new Date().toISOString()" will input the current time for the driver change. When conducting these driver changes through the SDK or through the UI, the new driver will only be assigned to this vehicle for trips moving forward. In other words, if the vehicle is currently on a trip, and you assign a new driver to this vehicle with a "dateTime" of the current date and time, the driver will not be assigned to the vehicle until the beginning of the next trip. 

Let me know if you have any other questions or concerns,

Christoph

Christoph Middleton 0 votes
0
Avatar

Hi,

I would just like to clarify my last statement about how drivers are assigned in MyGeotab. 

If a driver is assigned to a vehicle while the vehicle is driving, the driver will be assigned for the current trip. If the driver is assigned to a vehicle during a stop, the driver will be assigned to the vehicle for the next trip.

Sorry for the confusion,

Christoph

Christoph Middleton 0 votes