In my database I have parameters for disable VIN and accelerometer reset, but I want to know which units have the parameter active.
You need to be logged in to reply to this post and participate in the Geotab Community discussions.
Hello @****-6175 ,
Thank you for your question and welcome to the Geotab Community! Great to have you here.
This is an interesting one! I believe you may be able to get this information through the API by pulling all your devices and checking the customParameters property on each GoDevice object. Give this a try in the https://my.geotab.com/apidemo/ and see if it returns what you're looking for:
api.call("Get", {
typeName: "Device",
search: {
fromDate: new Date().toISOString()
}
}, function(devices) {
var devicesWithParam = devices.filter(function(device) {
return device.customParameters && device.customParameters.length > 0;
});
console.log("Devices with active custom parameters:");
devicesWithParam.forEach(function(device) {
console.log(device.name, device.serialNumber, device.customParameters);
});
}, function(error) {
console.error(error);
});
Let us know what comes back if customParameters isn't populated in the response, we can see if there are any alternatives.
Please let us know if you have any other questions. We are here to help.
Have a great day!
Eishi FUN
Hello @****-6175 ,
Thank you for your question and welcome to the Geotab Community! Great to have you here.
This is an interesting one! I believe you may be able to get this information through the API by pulling all your devices and checking the customParameters property on each GoDevice object. Give this a try in the https://my.geotab.com/apidemo/ and see if it returns what you're looking for:
api.call("Get", {
typeName: "Device",
search: {
fromDate: new Date().toISOString()
}
}, function(devices) {
var devicesWithParam = devices.filter(function(device) {
return device.customParameters && device.customParameters.length > 0;
});
console.log("Devices with active custom parameters:");
devicesWithParam.forEach(function(device) {
console.log(device.name, device.serialNumber, device.customParameters);
});
}, function(error) {
console.error(error);
});
Let us know what comes back if customParameters isn't populated in the response, we can see if there are any alternatives.
Please let us know if you have any other questions. We are here to help.
Have a great day!
Eishi FUN
Hi! @EishiFUN
Thanks for the reply, the code was helpful. I'm also sharing a modified code that helped me summarize which units have the parameter active:
api.call("Get", {
typeName: "Device"
}, function(devices) {
var targetDescription = "Reset Accelerometer Calibration On Power Up";
var results = [];
devices.forEach(function(device) {
// Buscamos dentro del arreglo customParameters si existe el objeto con esa descripción
if (device.customParameters && Array.isArray(device.customParameters)) {
var hasParam = device.customParameters.some(function(param) {
return param.description === targetDescription && param.isEnabled === true;
});
if (hasParam) {
results.push({
Nombre: device.name,
SerialNumber: device.serialNumber,
ID: device.id,
VIN: device.vehicleIdentificationNumber || "N/A"
});
}
}
});
console.log("--- REPORTE DE CALIBRACIÓN DE ACELERÓMETRO ---");
console.log("Dispositivos analizados: " + devices.length);
console.log("Dispositivos con el parámetro activo: " + results.length);
console.log("----------------------------------------------");
if (results.length > 0) {
// Generar formato CSV para copiar
var csv = "Nombre,SerialNumber,ID,VIN\n";
results.forEach(function(r) {
csv += '"' + r.Nombre + '","' + r.SerialNumber + '","' + r.ID + '","' + r.VIN + '"\n';
});
console.log("COPIA EL SIGUIENTE TEXTO PARA EXCEL:");
console.log(csv);
} else {
console.log("No se encontraron dispositivos con este parámetro habilitado.");
}
}, function(error) {
console.error("Error en la API:", error);
});
Regards.