Hi experts,
I am using scripting to on a field called "new_timer" that acts as a timer triggered when any field on the record changes. I use getIsDirty Method, but the timer is still starting as soon as I open some record and not when a field changes.
//Initialize time attributes
var seconds = 0, minutes = 0, hours = 0,t;
var myVar = setInterval(add, 2000);
function add()
{
var oppAttributes = Xrm.Page.data.entity.attributes.get();
if (oppAttributes != null)
{
for (var i in oppAttributes)
{
if (oppAttributes[i].getIsDirty())
{
seconds++;
if (seconds >= 60)
{
seconds = 0;
minutes++;
if (minutes >= 60)
{
minutes = 0;
hours++;
}
}
clearTimeout(myVar);
}
}
}
//creating time value in hh:mm:ss formate
var tmp = (hours ? (hours > 9 ? hours : "0" + hours) : "00") + ":" + (minutes ? (minutes > 9 ? minutes : "0" + minutes) : "00") + ":" + (seconds > 9 ? seconds : "0" + seconds);
Xrm.Page.getAttribute("new_timer").setValue(tmp);
//recursively calling timer
timer();
}
//main timer method
function timer() {
t = setTimeout(add, 1000);
}
Is there anything missing in my code that I should add?
Thanks,
Jon
*This post is locked for comments
I have the same question (0)