To generate a random serial number, based on a given mask, you can use the following code: // Serial Number Generator // Generates a random number in a certain interval function GenerateRandomNumber(min,max) { return Math.floor(Math.random() * (max – min + 1)) + min; } // Generates a random alphanumberic character function GenerateRandomChar() { var chars… Continue reading JavaScript Serial Number Generator
Category: JavaScript
Useful JavaScript functions & methods for CRM 2011 – CWS.CRM.Utils.js Library
Starting with this great article, I’ve created a JavaScript Library with several useful functions & methods for CRM 2011, such as: – CRM Service class to Create, Update, Retrieve, RetrieveMultiple, Delete records in CRM (SOAP based); – Custom Runtime Advanced Filtered Lookup support; – Set Lookup Value programmatically support – Guid Generator – CRM Form Buttons… Continue reading Useful JavaScript functions & methods for CRM 2011 – CWS.CRM.Utils.js Library
Generate a new Guid in JavaScript
As easy as that 🙂 // Generate new Guid function Hexa4() { return (((1+Math.random())*0x10000)|0).toString(16).substring(1); } function GenerateGuid() { return (Hexa4()+Hexa4()+”-“+Hexa4()+”-“+Hexa4()+”-“+Hexa4()+”-“+ Hexa4()+Hexa4()+Hexa4()).toUpperCase(); } // USE var guid = GenerateGuid(); alert(guid);
Creating records in CRM 2011 using JavaScript
Using the CRM Web Service, you can create new entity records, just using JavaScript. The following code demonstrates this: // Make Struct function MakeStruct(names) { var names = names.split(‘ ‘); var count = names.length; function constructor() { for (var i = 0; i < count; i++) { this[names[i]] = arguments[i]; } } return constructor; }… Continue reading Creating records in CRM 2011 using JavaScript
JavaScript structures
Here’s a brief example of how to create structures in JavaScript. We’ll use this function a lot from now on in our code. // Make Structfunction MakeStruct(names) { var names = names.split(‘ ‘); var count = names.length; function constructor() { for (var i = 0; i < count; i++) { this[names[i]] = arguments[i]; } }… Continue reading JavaScript structures
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… Continue reading JavaScript code reuse in CRM
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… Continue reading Large Integer division remainder
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… Continue reading OnChange Event
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) {… Continue reading Random Custom Serial Number Generator
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 onesfunction ReplaceChars(oldValue,newValue) { var newText = this.split(oldValue); newText = newText.join(newValue); return newText;} // Attach the custom method to string objectString.prototype.Replace = ReplaceChars; // Usagevar myString = “Hello World!”;alert(myString.Replace(“o”,”0″)); // will… Continue reading Replace Chars in String – prototype example