Reference fields at time of day

I’m a novice at Velo and having trouble figuring the code to return text and url from a reference dataset depending on time of day.

What I want to do…

We partner with clients (listed in the main dynamicDataset) and offer them wellbeing practices (listed in the second Practices dataset).

I want a text box (#text314) to be populated by looking into the main dataset (dynamicDataset) for a field (em1Practice) which references a second dataset (Practices) and to return a field in this dataset (‘instruction’).

What I’ve tried…

I have been able to do this using only the main dynamicDataset (copy of sample code below), but I would need 60 fields in the main dataset and it’s less flexible for changing over time or replicating.

So I want to use the second ‘Practices’ reference dataset to list all the possible practices to select from each with the five data fields above. It keeps things cleaner.

Question…

How would I edit the code below for it to look for the ‘instruction’ field in the second Practices dataset, referenced in the ‘em1Text’ field in the the main dynamicDataset.

$w.onReady(function () {
    $w("#dynamicDataset").onReady(function(){

const date = new Date();       
const hour = date.getHours();  

if(hour <= 9){               
  $w("#text314").text = $w("#dynamicDataset").getCurrentItem().em1Text;  
}else if(hour >= 9 && hour < 12){ 
  $w("#text314").text = $w("#dynamicDataset").getCurrentItem().mm1Text;
}else if(hour >= 12 && hour < 18){
  $w("#text314").text = $w("#dynamicDataset").getCurrentItem().a1Text;
}else{
  $w("#text314").text = $w("#dynamicDataset").getCurrentItem().e1Text;
}              
    })
    })