web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

Scripting error: Function not defined at eval

(0) ShareShare
ReportReport
Posted on by

Hi experts,

I have used scripting to run an active timer on field new_timer, triggered when any field changes on the form using getIsDirty()

I'm getting this scripting error, although I can't find any error in my code.

1321.Screen-Shot-2018_2D00_03_2D00_07-at-11.40.50-AM.png

//Initialize time attributes
var seconds = 0, minutes = 0, hours = 0,t;
var myVar = setInterval(add, 2000);
function add() 
{
	//var flag = Xrm.Page.getAttribute("new_timerstatus").getValue();
	//if (flag == "1")
	//{
	//get list of dirty fields
    oppAttributes = Xrm.Page.data.entity.attributes.get();
    if (var 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);
}

/*function onLoad()
{
		Xrm.Page.getAttribute("new_timerstatus").setValue("1");
}*/


Please help me out as I'm unable to figure out the problem.

Thanks,

Jon

*This post is locked for comments

I have the same question (0)
  • Alex Fun Wei Jie Profile Picture
    33,628 on at

    Hi,

    extra } ?.

    Ps : i accidentally put an extra }

  • Community Member Profile Picture
    on at

    Hi Wei Jei, 

    I think the number of } are correct

    //Initialize time attributes
    var seconds = 0, minutes = 0, hours = 0,t;
    var myVar = setInterval(add, 2000);
    function add() 
    {
    	//var flag = Xrm.Page.getAttribute("new_timerstatus").getValue();
    	//if (flag == "1")
    	//{
    	//get list of dirty fields
        oppAttributes = Xrm.Page.data.entity.attributes.get();
        if (var 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);
    }
    
    
    
    
    


  • Verified answer
    Alex Fun Wei Jie Profile Picture
    33,628 on at

    Hi,

    this part , should be

    var oppAttributes = Xrm.Page.data.entity.attributes.get();
    if ( oppAttributes != null)

    8322.7.png

  • Community Member Profile Picture
    on at

    Hi,

    Still getting the same error.

    Thanks.

  • Community Member Profile Picture
    on at

    Could it be because of the ClearTimeout and SetTimeout ?

  • Alex Fun Wei Jie Profile Picture
    33,628 on at

    Hi,

    where is your ClearTimeout and SetTimeout function?

    i didnt debug until that steps.

  • Community Member Profile Picture
    on at

    Hi,

    Line 29, Line 47 respectively

    //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);
    }
    
    
    
    
    


  • Alex Fun Wei Jie Profile Picture
    33,628 on at

    Hi,

    you can try, could be.

  • Suggested answer
    jdalske Profile Picture
    547 on at

    In the event this helps any one.  I was getting a similar error.  

    ReferenceError: FormOnLoad is not defined

       at eval (eval at RunHandlerInternal (http://...

    It ended up that this var statement : var formContext = executionContext.getFormContext();

    needed to be moved a few lines down somewhere below this statement.  function FormOnLoad(executionContext).  The order I had it is was at the top which worked in other forms but not this one due to the order the other references were being made.

    Hope that helps.

    This site was also extremely helpful in fixing my XRM.Page references.

    www.crmug.com/.../viewthread

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
SA-08121319-0 Profile Picture

SA-08121319-0 4

#1
Calum MacFarlane Profile Picture

Calum MacFarlane 4

#3
Alex Fun Wei Jie Profile Picture

Alex Fun Wei Jie 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans