Cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Goals and Cannot read property 'steps' of undefined

ANSWERED

Hi guys,

 

I am trying to access the goal number for steps and I am getting the error 'Cannot read property 'steps' of undefined' when running the code on the simulator. I have activated permissions for Activity. Any idea what I am doing wrong?

 

Below is my code:

 

index.js

import clock from "clock";
import document from "document";
import { preferences } from "user-settings";
import * as util from "../common/utils";

import { me as appbit } from "appbit";
import { goals } from "user-activity";


// Update the clock every minute
clock.granularity = "seconds";

// Get a handle on the <text> element
const myLabel = document.getElementById("myLabel");

// Update the <text> element every tick with the current time
clock.ontick = (evt) => {
  let today = evt.date;
  let hours = today.getHours();
  if (preferences.clockDisplay === "12h") {
    // 12h format
    hours = hours % 12 || 12;
  } else {
    // 24h format
    hours = util.zeroPad(hours);
  }
  let mins = util.zeroPad(today.getMinutes());
  myLabel.text = `${hours}:${mins}`;
  

}

// Get goals  
if (appbit.permissions.granted("access_activity")) {
   console.log(`${goals.adjusted.steps} Step Goal`);
   if (goals.local.elevationGain !== undefined) {
     console.log(`${goals.adjusted.elevationGain} Floor Goal`);
   }
}

 

Best Answer
0 Votes
1 BEST ANSWER

Accepted Solutions

'adjusted' is not a member of 'goals'. See here.

Peter McLennan
Gondwana Software

View best answer in original post

Best Answer
2 REPLIES 2

'adjusted' is not a member of 'goals'. See here.

Peter McLennan
Gondwana Software
Best Answer

Good catch Catplace!

 

The example code in the documentation must have an error.

 

You are correct, calling goals.steps solves the problem.

 

if (appbit.permissions.granted("access_activity")) {
   console.log(`${goals.steps} Step Goal`);
   if (goals.elevationGain !== undefined) {
     console.log(`${goals.elevationGain} Floor Goal`);
   }
}

 

harpo666_0-1581293552668.png

 

Best Answer