Develop Secure Code
HealthService Data Types
getHealthService()
isAvailable()
getWeight(options)
writeWeight(record)
writeWeight(record)Writes a body-weight record to the device’s health store. If needed, presents a permissions prompt to the user to request access to health data first, and then writes the record.
1import { getHealthService } from 'lightning/mobileCapabilities';
2writeWeight(record: WeightRecord): Promise<void>record—(Required) A WeightRecord object that represents the weight measurement to write. Provide a value greater than 0 and a valid unit.A resolved promise returns no object.
A rejected promise returns a HealthServiceFailure object containing details about the error.
This function writes a single weight record to the device’s health store.
1const record = {
2 value: 80.5,
3 unit: 'kg',
4 startTime: Date.now(),
5 endTime: null
6};
7myHealthService
8 .writeWeight(record)
9 .then(() => {
10 console.log("Weight record saved.");
11 })
12 .catch((error) => {
13 console.error("Error code: " + error.code);
14 console.error("Error message: " + error.message);
15 });then clause.catch clause.HealthServiceFailure.code value of USER_DENIED_PERMISSION.See Also