How to get the resting heartrate of the day for the last 7 days ?

Hello,
I am trying to read the resting heartrate of the day for the last 7 days, i.e. the resting hertrate of yesterday, the day before, etc.

I tried so far with "ActivityMonitor.getHeartRateHistory(null, true);". However, I only seem to get today. Does anyone have experience with this and can give me a tip? That would be really great.
Here is the code of my function:

----------------------------------------------------------

function Get_RestHR()
    {
        var _restHR_seven = new [7];
        var hrmin = 100;
        var refday = Gregorian.info(Time.now(), Time.FORMAT_SHORT);
        var index = 6;

        var hrIterator = ActivityMonitor.getHeartRateHistory(null, true);
        var sample = null;
        do {
                sample = hrIterator.next();
                if (null != sample) {                               // null check
                    if (sample.heartRate != ActivityMonitor.INVALID_HR_SAMPLE) {
                        var _day = Gregorian.info(sample.when, Time.FORMAT_SHORT );
                        System.println(_day.year + "/" + _day.month + "/" + _day.day + " - " + _day.hour + ":" + _day.min + ":" + _day.sec);

                        if(hrmin > sample.heartRate){
                            hrmin = sample.heartRate;
                            _restHR_seven[index] = sample;

                            System.println("Sample restHR: " + sample.heartRate);
                        }

                            if(_day.year < refday.year){
                                refday = _day;
                                hrmin = 100;
                                index -=1;
                            }
                            else if(_day.month < refday.month){
                                refday = _day;
                                hrmin = 100;
                                index -=1;
                            }
                            else if(_day.day < refday.day){
                                refday = _day;
                                hrmin = 100;
                                index -=1;
                            }
                       
                    }
                }

                if(index < 0){
                break;}
        }
        while (sample!= null);

        return _restHR_seven;
    }
---------------------------------------------------------------------------