Monday, October 20, 2008

JavaScript code reuse in CRM

In most of the cases, you don't want to copy-paste your custom methods in your CRM events source code each time you need them.

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.

Monday, September 08, 2008

Welcome Tavi

Let's give a big welcome to our newest author - Mr. Octavian Cucuta on CRM Stuff blog. He promises a lot :P

Large Integer division remainder

Recently, I had to obtain the remainder of a (seriously) large integer division (32 digits long divided by another shorter integer; base 10) and found that JavaScript reliably supports operations only on 15-digit long integers. Thus, this what I came up with:

// Gets the remainder from the division operation for LARGE numbers
// Support: positive integers; first parameter must not be 0
function GetRemainder(x, y) {
if ((y != 0) && (x.slice(0, 1) != "-") && (y.slice(0, 1) != "-"))
var nr = x;

// Removing the potential first '+' character
if (nr.slice(0, 1) == "+") {nr = nr.slice(1);}
if (y.slice(0, 1) == "+") {y = y.slice(1);}

// Removing leading blank and tab characters on both numbers
while ( (nr.charCodeAt(0) == 32) || (nr.charCodeAt(0) == 9) ){
nr = nr.slice(1);
while ( (y.charCodeAt(0) == 32) || (y.charCodeAt(0) == 9) ){
y = y.slice(1);

var len = nr.length;

// Checking if any non-digit characters are embedded into the input string
var i = 0;
for (i = 0; i < len; i++)
if (!((nr.charCodeAt(i) >= 48) && (nr.charCodeAt(i) <= 57)) ) {
return -1;

var number = parseInt(y,10);
var remainder = 0;
var ignore = 0;
var k = '';

while (ignore < len) {
if (remainder == 0) {
var w1 = y+' ';
var w2 = w1.length-1;
k = nr.slice(ignore, ignore+w2);

ignore += w2;
remainder = parseInt(remainder+k, 10) % number;
} else {
k = nr.slice(ignore, ignore+1);
ignore += 1;
remainder = parseInt(remainder+k, 10) % number;

return remainder;

return -1;


document.write(GetRemainder("12345678901234567890123456789012", "123"))

will output 27.

Friday, September 05, 2008

OnChange Event

When starting to work with CRM, one of the first things you learn is how to put some script on the onChange event. It's easy to do this and it really works.
Let's say you want to fire that script at the first moment your page is loaded.
In CRM 3.0 you could do that writing a single line :
When starting to work with CRM 4.0 I tried to use the same code but it didn't work anymore. I was sooooo disappointed and I hardly found out the solution. That's why i thought of sharing it with you.
The code for firing a script put on the onchange event for CRM 4.0 is:

I hope this helps. Happy coding! :)

Random Custom Serial Number Generator

A brief example on how to generate random serial numbers with JavaScript. Enjoy!

// Symbols Array (A-Z, 0-9)
var Symbols = new Array();

// Gets the ascii code for a certain character
function GetAsciiBySymbol(letter)
var code = letter.charCodeAt(0);
return code;

// Populates a certain array with the A-Z, 0-9 symbols
function PopulateArray(array) {
var Position = 0;

// Letters
for(i=GetAsciiBySymbol('A'); i<=GetAsciiBySymbol('Z'); i++) {

array[Position] = String.fromCharCode(i);

// Numbers
for(i=GetAsciiBySymbol('0'); i<=GetAsciiBySymbol('9'); i++) {
array[Position] = String.fromCharCode(i);


// Gets the array symbol by a certain index
function GetSymbol(index) {
return Symbols[index];

// Generates a new Serial Number
function GenerateSerial(serialLength, separatorSymbol, separatorPositions) {
var serial = "";
var Offset = 0;

for(i=0; i
var rnd = Math.floor(Math.random()*Symbols.length);
serial += GetSymbol(rnd);

if(SeparatorPositionsOk(separatorPositions,serialLength)) {
for(i=0; i
var position = separatorPositions[i];
serial = serial.substring(0,position + Offset) + separatorSymbol + serial.substring(position + Offset, serial.length); Offset++;

return serial;

// Checks if a certain array contains only items less than a maximum value
function SeparatorPositionsOk(array, maxValue) {
for(i=0; i maxValue) {
return false;

return true;

// Populate Symbols

var SepPos = new Array();
SepPos[0] = 5;
SepPos[1] = 10;
SepPos[2] = 15;
SepPos[3] = 20;
var NewSerial = GenerateSerial(25, "-",SepPos);
alert("Serial Number: " + NewSerial);

SepPos = new Array();
SepPos[0] = 8;
SepPos[1] = 12;
SepPos[2] = 16;
SepPos[3] = 20;
SepPos[4] = 24;
NewSerial = GenerateSerial(32, "-",SepPos);
alert("Serial Number: " + NewSerial);

// Example 3 - Format: XXX-XXXXXXX
SepPos = new Array();
SepPos[0] = 3;
NewSerial = GenerateSerial(10, "-",SepPos);
alert("Serial Number: " + NewSerial);

Replace Chars in String - prototype example

An elegant way to replace certain chars from a string with new ones:

// Custom method for replacing certain chars from a string with new ones
function ReplaceChars(oldValue,newValue) {
var newText = this.split(oldValue);
newText = newText.join(newValue);
return newText;


// Attach the custom method to string object
String.prototype.Replace = ReplaceChars;

// Usage
var myString = "Hello World!";
alert(myString.Replace("o","0")); // will output "Hell0 W0rld!"

An easier way to hide or show a certain field in CRM

Simply use the function below:

// Shows or hides a certain field
function HandleField(field, display) {
document.getElementById(field+"_c").style.display = display;
document.getElementById(field+"_d").style.display = display;

/* Calling */
HandleField("fieldid", "inline"); // show inline
HandleField("fieldid", "block"); // show block
HandleField("fieldid", "none"); // hide

Wednesday, February 27, 2008

Create a button on your form

This is an example on how to create a button on the form, based on a former idea of Cornel. First of all we need to create a nvarchar attribute and put it on the form where we want our button. I assume that everybody knows how to create an attribute and put in on the form, so i won't talk about this.
In this example my attribute's schema name is new_button. Here is the code:

// This is how we call the button, what we see
crmForm.all.new_button.DataValue = "Ok";
// We could align it a bit = "center";
crmForm.all.new_button.vAlign = "middle";
//we make the mouse look as a hand when we're moving over = "hand"; = "#CADFFC"; = "#FF0000"; = "#330066"; = "bold";
crmForm.all.new_button.contentEditable = false;
//we attach some events in order to make it look nice :)
function color3() { = "#6699FF";
function color4() { = "CADFFC";
function color1() { = "000099";
function color2() { = "FF0000";
//here we attach what we want our button do
Here is how the button looks like:

I didn't define here the "someFunction", i leave it up to you. First time when i used such a button was to add product to a quote without click-ing on "New Quote Product", calling a Web Service...

Monday, February 18, 2008

Welcome Alex

Welcome Mr. Alexandru Radu on CRM Stuff blog. Alex is a CRM Project Manager, Consultant, Trainer and also a MCP, with lots and lots of CRM experience.

Thursday, February 14, 2008

Welcome Adi

Let's give a warm welcome to our newest author - Mr. Adrian Toderut on CRM Stuff blog. He's a very good consultant with a lot of experience in Microsoft Dynamics CRM.

Tuesday, February 05, 2008


Well, like I said, I'm back in business and I promise that asap I'll post a few useful ideas. I'd like to think that 2008 will be the year of CRM in Romania and not only, as MS Dynamics CRM Titan will replace, step by step, CRM 3.0. Stay tuned...

P.S. Thanks Microsoft for the MCP in Business Solutions, looks nice :)

Friday, February 01, 2008

Nofollow - free

Blogger by default, and other blogging software such as WordPress, automatically adds the "nofollow" microformat extension to all links from user generated content. User generated content is defined as comments or external sources such as linkbacks and trackbacks.

I support the people of the blogging community who have chosen to remove NoFollow for blog comments and linkbacks/trackbacks and I highly recommend others to do so.

Removing the "nofollow" attribute will help people who are giving you comments to increase their website/blog PR (Page Rank). I currently set the lower limit to 1 for my blog, so feel free to comment, 1 comment/user will help you raise your PR :)

If you want to learn more about this feature, try the following links:

Click here for blogspot/blogger

Click here for WordPress

Thursday, January 10, 2008


Considering the fact that the examining session at the college has begun for me, I'll suspend the posting around here for a while (until february 2008). I promise to be back with new useful features asap. Good luck!

Sunday, January 06, 2008

World without Romania

And here are some relevant images (I'd like to think) about my country:


Friday, January 04, 2008


I'd like to introduce Andrei Gabur's Blog. It's an interesting blog about philosophy and history. Give it a look when you've got the time :)

Tuesday, January 01, 2008

Small Business Loan

If you are seeking money in the form of an unsecured small business or personal loan, you have located a useful source to assist with your financing needs. America One is what you're looking for. In the past year alone, they’ve helped their clients receive millions in approvals.By using this great service - Small Business Loans, you benefit from extensive knowledge of today's most active lending sources. Their specialty product is a signature loan that can be used for any purpose, with no collateral required. Approval is based upon your current credit standing.

Why use America One?

First and foremost when you borrow money, you want to be sure you are applying with a company you can trust. At America One Funding, they have been providing consumers and small business owners’ fair and equal access to unsecured financing nationwide since 1999. It seems these days that almost every financial website claims to be the biggest and best, but in their case it is a fact. They are the largest unsecured loan consulting and placement firm in the nation for seven consecutive years, assisting over 500,000 applicants per year.

While they are proud of their growth, they also work hard to maintain the entrepreneurial grassroots approach to financing that has led to their success. When you work with America One, you will receive superior and accessible service from a highly trained unsecured financing expert. You will find them compassionate to your unique situation, but also willing to speak to you in realistic terms about your loan options. They will never tell you what you want to hear, just to get your business. In addition, unlike many other banks and finance companies, they are exclusively dedicated to unsecured financing, which leads to higher approval rates and better overall customer satisfaction.

At America One, the business philosophy can be summed up by one simple question; why risk your valuable assets to borrow money if you don’t have to? When you allow them to help you, your unsecured loan request will have best possible chance of being approved for the amount of money you need, and at rate and term you can afford. It only takes a few minutes to pre-qualify and you can have money in hand as fast as a few days.

The professional staff is available for a free consultation. Start by clicking the service most suitable for you, right after you visit Small Business Loan website.