Two simple bits of code can't coexist together - I'm clearly doing something stupid

//const shiftstart = msg.payload.shift_start.timestamp;
//const clockin = msg.payload.clockin_time.timestamp;
//const timeDifference = shiftstart - clockin;
//const timeDifference2 = clockin - shiftstart;
var breakd = msg.payload.duration
breakd = breakd.replace('m',"");
breakd = Number(breakd);
msg.payload.woo2 = breakd;
//    if ((timeDifference/60).toFixed(0) >= 3){
//        msg.payload = msg.payload.name +" was " + (timeDifference/60).toFixed(0) + " minutes early today";
//    } else if ((timeDifference/60).toFixed(0) < 3){
//        msg.payload = msg.payload.name +" was " + (timeDifference2/60).toFixed(0) + " minutes late today";
//    }
  if (breakd < 25) { msg.payload.woo = "over 25"}
    else {msg.payload.woo = "under 25"}  
return msg;

If I remove the comment slashes, msg.payload.woo2 goes 'undefined' - if I keep them in, I get a number.

Confusing what about the commented out code is somehow overwriting msg.payload.woo2

Anyone know?! Thanks

You set msg.payload to a string in that commented out code...
image

a string cannot have user properties

THANK YOU! :slight_smile: :slight_smile:
I've spent ages on this. Much appreciated.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.