locked
Small javascript problem passing variables, Code inside. Please assist. RRS feed

  • Question

  • I have the javascript below, the weird thing is it just stopped working this morning. When I try to set the field "new_seconds", I always get a 0. I've declared a global variable so I should be able to pass paramteres between functions but I always get a 0. I don't know what went wrong this morning.

    var i = 1;
    var MSeconds = 0;
    
    function onLoad() {
    
        _Timer();
    }
    
    function _Timer () {  
       setTimeout(function () { 
          MSeconds = MSeconds + 1; 
          alert(MSeconds);
          i++;                
          if (i > 0) { 
                 
             _Timer();        
          }                        
       }, 1000)
    }
    
    function onSave() {
    
        Xrm.Page.data.entity.attributes.get("new_seconds").setValue(MSeconds);
    }
    

    Anyone know how to fix this?

    Thursday, June 20, 2013 8:04 PM

All replies

  • Andrea,

    If there were no changes to the script then the likelihood of it just stop working is unlikely.  The first thing I'd check is to make sure no one removed your event registration on the form that triggers your onLoad() call.  This might explain why the global variable is still the default "0" when the onSave() is called.

    Let me know the results of checking the onLoad() event registration...

    Rick Gipson
    Credera

    Friday, June 21, 2013 5:12 AM