Hello, there :-)
Have you ever encountered this situation? You write some decent, valid JS code, throw it inside a CRM field event box, Save & Close x2, publish, test, BAM!-error?
Well, provided your code is actually correct (no logical, typing or access errors), you should check the next thing. In CRM 3.0 at least (not having a 4.0 box around atm., feel free to test if you're kind enough) if you load a piece of code having its last line using a line comment, you're in for trouble. I was lucky to find that out while debugging a whole page and noticed that the line comment I was using was extended to the rest of the CRM JS code (due to CRM placing the CATCH(e){} part of the TRY{} block right on the same line with the last line of my code). That was causing havoc to the entire page.
So, remember this hint: never leave the last line of code having a line comment ( "//" ) or you're in for trouble :D
Cheers!
Thursday, December 31, 2009
MS CRM 3.0 "Expected '}'" and "Object expected" errors
Publicat de
BlackDoom
la
2:37:00 PM
4
comentarii
Etichete: 3.0, all, crm, error, expected, JavaScript, JavaScript Events
Monday, October 20, 2008
JavaScript code reuse in CRM
So, here's an easy approach on javascript code reuse in CRM.
First of all, make sure you have these 2 files: LargeNumber.js and StringsExtended.js located in a custom folder - named CRMStuff - that is also located in the root folder of the Microsoft Dynamics CRM server application (the relative paths to the files should be "/crmstuff/LargeNumbers.js" and "/crmstuff/StringsExtended.js"). As you can see, these 2 files contain custom methods.
Click here to download the source code that allows you to load your *.js files at runtime.
Sunday, December 02, 2007
Generating tooltips on certain events
A tooltip is a small box of explanatory text (usually on yellow background) that appears when the mouse pointer is held over a button or other interface element.
In Microsoft Dynamics CRM we can define constraints (masks) on certain fields. It is desired that the user is well informed about the text’s format, in real time, when triggering the onmousemove event on a certain field.
In this tutorial, we show you a function that generates tooltips on CRM’s forms, triggered by mouse events, such as: onclick, ondblclick, onmouseover, onmousedown and especially, onmousemove.
The links for this tutorial are:
English version --> click here
Romanian version --> click here
Here are some prints (examples) of different types and styles of tooltips made with the function presented in this tutorial:
Account Entity - Account Name - onmousemove event

Account Entity - Primary Contact - onmousemove event

Account Entity - Body - ondblclick event

Account Entity - Account Number - onmousemove event (default Windows style)

We hope you found this solution useful :) If you find, by any chance, any mistakes in the tutorial, please let us know. Thank you.
Publicat de
CSC
la
10:42:00 AM
4
comentarii
Etichete: all, crm, JavaScript, JavaScript Events, news, Tutorials
Saturday, November 17, 2007
Using the "onmousemove" event
The "onmousemove" event can help you make sure that your script runs as well as your cursor on the form :) I'll give you a brief example of its usage. We want to trap the cursor's coordinates as it moves in a certain entity's form in CRM.
Add the following code on the OnLoad() event of a form you want:
document.onmousemove = function() {
window.status = event.clientX + "x"+event.clientY;
}
Of course, you may attach the "onmousemove" event to the crmForm too, using:
crmForm.onmousemove = function() {
window.status = event.clientX + "x"+event.clientY;
}
But this way, your status will update only if your cursor moves inside the crmForm, not in the entire window like in our first example.
Saturday, November 10, 2007
Using the "onkeyup" event
Let's add some interactivity to our customizations :) For example, we have 4 fields: Amount (Schema Name amount, Type float(2)), Discount
(Schema Name discount, Type float(2)), Tax (Schema Name tax, Type float(2)) and Total Amount (Schema Name totalamount, Type float(2)) and we
want to calculate in real time the Total Amount based on the Amount, Discount and Tax.
First let's consider the following formulas:
Tax = 1.19 * Amount
Discount - between 1 and 100 (percentage of Amount)
Total Amount = (100 - Discount)/100 * Amount + Tax
Second, we create the function that calculates the Total Amount on the basis of the other 3 and we type the following code on the OnLoad() event of a form which contains our fields:
function updateTotalAmount() {
var amount = crmForm.all.amount.DataValue;
var discount = crmForm.all.discount.DataValue;
var tax = crmForm.all.tax.DataValue;
var total;
tax = 0.19 * amount; //we assume that the tax represents 19% of the amount
total = (100 - discount) / 100 * amount + tax;
crmForm.all.tax.DataValue = tax;
crmForm.all.totalamount.DataValue = total;
}
And now, we attach an "onkeyup" event to the amount, discount and tax fields. The event will call our function, like this:
crmForm.all.amount.attachEvent("onkeyup",updateTotalAmount);
crmForm.all.tax.attachEvent("onkeyup",updateTotalAmount);
crmForm.all.discount.attachEvent("onkeyup",updateTotalAmount);
Now, we may test the interactivity of our form. Type a value for the Amount and Discount fields and you'll see, in real time, how the Total Amount field updates.
Here's a printscreen of our example:
Saturday, October 27, 2007
Events in JavaScript
Therefore JavaScript needs a way of detecting user actions so that it knows when to react. It also needs to know which functions to execute, functions that do something that you, the web developer, have judged likely to increase the appeal of your pages. These pages describe the best way to write such scripts. It isn’t easy, but it is very satisfying work.
When the user does something an event takes place. There are also some events that aren’t directly caused by the user: the load event that fires when a page has been loaded, for instance.
There are various types of events, such as:
1. Interface Events: onfocus/onblur, oncontextmenu, onload/onunload, onscroll, onresize;
2. Mouse Events: onclick, ondblclick, onmousedown/onmouseup, onmouseenter/onmouseleave, onmouseover/onmouseout, onmousemove, onmousewheel;
3. Form Events: onchange, onreset, onselect, onsubmit;
4. Keyboard Events: onkeypress, onkeydown/onkeyup;
5. Miscellaneous Events: onabort, onerror, onerrorupdate, ontimeerror, onsubtreemodified, onactivate/ondeactivate, onbeforeactivate/onbeforedeactivate, onbeforeprint/onafterprint, onbeforeupdate/onafterupdate, onbeforecut, onbeforecopy, onbeforepaste, oncut, oncopy, onpaste, onpropertychange, onreadystatechange, onresizestart/onresizeend, oncontrolselect, onselectstart, onselectionchange, onbounce, onfocusin/onfocusout, onbeforeeditfocus, onlosecapture, oncellchange, ondrag, ondragenter/ondragleave, ondragover, ondragstart/ondragend, ondrop, onmove, onmovestart/onmoveend, onlayoutcomplete, ondataavailable, ondatasetchange, ondatasetcomplete, onfilterchange, onrowenter, onrowexit, onrowsdelete, onrowsinserted, onstart/onfinish, onhelp, onbeforeunload.
In Microsoft Dynamics CRM, the syntax for using an event is:
crmForm.all.schema_name.attachEvent('event_name',func);
function func() {
//code
}
or
crmForm.all.schema_name.onevent = function() {
//code
}
For example, if you want to display the label for a certain field in CRM when you click the field, all you have to write is one of the following codes on the OnLoad() event:
1. crmForm.all.schema_name.attachEvent('onclick',showLabel);
function showLabel() {
alert(crmForm.all.schema_name_c.innerHTML);
}
2. crmForm.all.new_camp.onclick = function() {
alert(crmForm.all.new_camp_c.innerHTML);
}
Enjoy testing the other events. I’m sure you’ll find them very useful ;)























