Develop Secure Code
HealthService Data Types
getHealthService()
isAvailable()
getWeight(options)
writeWeight(record)
getWeight(options)Reads body-weight records from the device’s health store. If needed, presents a permissions prompt to the user to request access to health data first, and then returns the records that match the options you provide.
1import { getHealthService } from 'lightning/mobileCapabilities';
2getWeight(options: GetWeightOptions|null): Promise<Array>options—A GetWeightOptions object to filter the records by time range, limit the number of records, and set the unit for the returned values. Pass null to use the defaults.A Promise object that resolves as an array of WeightRecord objects. If no records match, the array is empty.
A rejected promise returns a HealthServiceFailure object containing details about the error.
This function reads weight records from the device’s health store and returns them as an array.
1const options = {
2 startTime: null,
3 endTime: null,
4 limit: 10,
5 preferredUnit: 'kg'
6};
7myHealthService
8 .getWeight(options)
9 .then((results) => {
10 this.weightRecords = results;
11 })
12 .catch((error) => {
13 this.weightRecords = [];
14 console.error("Error code: " + error.code);
15 console.error("Error message: " + error.message);
16 });then clause.catch clause.HealthServiceFailure.code value of USER_DENIED_PERMISSION.preferredUnit. If you don’t set a unit, HealthService returns values in kilograms.See Also