Ga naar hoofdinhoud

Get Asset Custom Properties using MyGeotab SDK

pcoetzerhanab-2133
Oorspronkelijke plaatser

As part of the Geotab system settings, you can define a list of properties that could be applied to Assets (additional metadata fields that is stored with the Asset). How can I get these Asset Property fields and values using the SDK?

 

System Settings > Assets >  Custom Properties

Deelnemen aan het gesprek

Je moet ingelogd zijn om op dit bericht te reageren en deel te nemen aan de discussies in de Geotab Community.

Populaire antwoorden

In the C# NuGet SDK, any Entity that can have custom properties will implement the `ICustomizable<T>` generic interface, which exposes a `CustomProperties` property:

// Device is one of the Entities that implements ICustomizable<T> // Assuming you've retrieved your populated device... List<PropertyValue<Device>> customProperties = device.CustomProperties;   // Accessing keys (names) and values var firstProp = customProperties[0]; var propName = firstProp.Property.Name; var propValue = firstProp.Value;

 

5 antwoorden

In the C# NuGet SDK, any Entity that can have custom properties will implement the `ICustomizable<T>` generic interface, which exposes a `CustomProperties` property:

// Device is one of the Entities that implements ICustomizable<T> // Assuming you've retrieved your populated device... List<PropertyValue<Device>> customProperties = device.CustomProperties;   // Accessing keys (names) and values var firstProp = customProperties[0]; var propName = firstProp.Property.Name; var propValue = firstProp.Value;

 

pcoetzerhanab-2133
Oorspronkelijke plaatser

Hey @DarenPorter-1148​ 

 

Thanks for your feedback. Using your input I was able to get to the Asset Custom Properties. For anyone seeing this post in the future, here is a sample that you can run in the API Runner | MyGeotab | Geotab Developers:

 

 

var desiredDevices = ['b1']; api.call("Get",{ "typeName":"Device", }, function(devices) { devices.forEach(function(device){ if(desiredDevices.indexOf(device.id) > -1){ console.log(`Custom Properties for device ${device.serialNumber}`); device.customProperties.forEach(function(customProp){ //console.log(JSON.stringify(customProp)); var propName = String(customProp.property.name); var propValue = customProp.value console.log(`${propName}: ${propValue}`); }); } }); }, function(e) { console.error("Failed:", e); });

 

PC

No problem, I'm glad it helped!

 

Not directly related to your question, but for potential future readers - if you know you're only interested in one device (like in the example above), it's much more efficient to include a search in the Get call so only that Device gets returned:

api.call("Get", { "typeName": "Device", "search": { "id": "b1" } }, function(devices) { let device = devices[0]; console.log(`Custom Properties for device ${device.serialNumber}`); device.customProperties.forEach(customProp => { let propName = String(customProp.property.name); let propValue = customProp.value; console.log('${propName}: ${propValue}'); }); }, function(e) { console.error("Failed:", e); });

 

pcoetzerhanab-2133
Oorspronkelijke plaatser

PS - There is no way of getting these fields in a standard Geotab report (the Excel version)??

EishiFUN
Community-beheerder

You could do it with a customized report. You can view this document to find the headers for these custom properties you would need to add to the report: [PUB] MyGeotab Reports Columns/Headers

Heeft u nog vragen?