JavaScript this.contextObj Returns Nothing

Hi all, I'm using a HTML snippet with context to create a count-up timer based on a date-time attribute of an entity. The issue I have is that the function this.contextObj always returns empty. Why is that? I'm adding the code as well as screenshot of my set-up.   $( document ).ready(function() { try { if(document.getElementsByClassName('mx-name-TickingTime')!=null){ console.log("Text field found"); var htmlEl = document.getElementsByClassName('mx-name-TickingTime'); if(this.contextObj!=null){ console.log("Context object found"); var obj =this.contextObj; let t0 = obj.get("StartTime"); setInterval(setTime(htmlEl, t0), 1000); function setTime(htmlEl, t0) { var totalSeconds = Math.abs(t0.getTime() - new Date().getTime())/1000; htmlEl.innerHTML = totalSeconds; } } else{ console.log("Context object NOT found!"); htmlEl.innerHTML = "Context object NOT found!"; } } else { console.log("Text field NOT found!"); } } catch(e) { }});     Any help will be greatly appreciated!
1 answers

Hello Nico Mouton,
Get the context in a variable outside the conditional block as below and try, and also give 'Yes' for Refresh on context change and Refresh on context update.




if it still doesn’t work try modifying the code without Jquery and set content type as Javascript.