Dear Zant, thanks for your reply.
Below is a sample implementation for the resource count. we managed to get drivers count well but trailers and tags are returning null. please let me know if there is something that we overlooked.
function countResources() {
this.sess = wialon.core.Session.getInstance();
this.sess.loadLibrary("resourceDrivers");
this.sess.loadLibrary("resourceTags");
this.sess.loadLibrary("resourceTrailers");
// Define the search specification for unit groups
var spec_group = {
itemsType: "avl_resource",
propName: "sys_name",
propValueMask: "*",
sortType: "sys_name"
};
var flags_group = wialon.util.Number.or(wialon.item.Item.dataFlag.base, wialon.item.Resource.dataFlag.drivers, wialon.item.Resource.dataFlag.tags, wialon.item.Resource.dataFlag.trailers);
sess.searchItems(spec_group, true, flags_group, 0, 0, function (code, data) {
if (code) {
console.error("Error searching resources:", code);
return;
}
let totalDriversCount = 0;
let totalTrailerCount = 0;
let totalPassengersCount = 0;
for (let i = 0; i < data.items.length; i++) {
resID = data.items[ i ].getId();
if(!sess.getItem(resID))
{
console.log("Error: sess.getItem(resID)");
return;
}
let drivers = sess.getItem(resID).getDrivers();
if (drivers) {
totalDriversCount += Object.keys(drivers).length; // Count drivers
}
let trailers = sess.getItem(resID).getTrailers();
if (trailers) {
totalTrailerCount += Object.keys(trailers).length; // Count trailers
}
let passengers = sess.getItem(resID).getTags();
if (passengers) {
totalPassengersCount += Object.keys(passengers).length; // Count Passengers
}
}
// $("h4#resources-drivers-count").text(totalDriversCount);
console.log("Total drivers count:", totalDriversCount);
console.log("Total trailers count:", totalTrailerCount);
console.log("Total passengers count:", totalPassengersCount);
});
}