CRM JScript Bug

Sure, we all know how to write comments in JavaScr... I mean "JScript" - you just put this before your one-line comment: //.  Well, recently, I had a strange problem with some JScript.  I knew it was 100% correctly written, but it was throwing errors, saying I was missing an end bracket - }.  Weird, I thought, as I closed all my if/else statements and all my functions that I defined, (you know how to do that in CRM, right?  crmForm.MyFunctionName = MyFunctionName(){//stuff} and then you can use it throughout the rest of that same form's events - even on field events - by saying crmForm.MyFunctionName().) so I was really in a quandary.  I looked at the last line in my event handler, and it was a comment.  I.e.

 // The previous line did whatever

So, I moved that comment above the aforementioned line, and it worked!

So, what's the bug mentioned in the title?  You can't end your JScript event handlers with a comment, even if it's at the end of a line of code.  I.e. this is illegal:

alert("Hello, world!");
// Say hello to the world

As is this:

alert("Hello, world!"; // Say hello to the world

Just say this:

// Say hello to the world
alert("Hello, world!");

Pretty lame, I know, but it should save some readers some headaches.

Published 07-30-2007 5:45 PM by vbullinger

Comments

# re: CRM JScript Bug

maybe it didnt work because you didnt close the comment with a ; ?? i dont know-- is that more of a java thing?

Tuesday, September 04, 2007 8:29 AM by em

# re: CRM JScript Bug

The semi-colon would have been commented out, just like the swirly bracket was.

Tuesday, September 04, 2007 8:52 AM by vbullinger

# re: CRM JScript Bug

I wish I read your blog earlier, today I spent over an hour trying to count up all the { } that almost blind me.

Monday, October 29, 2007 3:43 PM by uew