Format date fields in CRM

Special thanks to Andriy a33ik Butenko for this post. // Formats the date into a certain format Date.prototype.Format = function(format) { var d = this; var f = “”; f = f + format.replace( /dd|mm|yyyy|MM|hh|ss|ms|APM|s|/|-|,|./ig , function match() { switch(arguments[0]) { case “dd”: var dd = d.getDate(); return (dd < 10)? "0" + dd :… Continue reading Format date fields in CRM

Create a custom filtered lookup view in runtime – CRM 2011

Starting CRM 2011 you can filter a certain lookup view based on related entities or other system/custom views. But sometimes this is not enough. For example, if you wanna make a custom filtered view, that uses several filters, you can use the following approach. Starting scenario (all of the completed lookup fields will be used… Continue reading Create a custom filtered lookup view in runtime – CRM 2011

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

Set a lookup value in CRM 2011

// Sets the lookup value for a certain field function SetLookupValue(fieldName, id, name, entityType) { if(fieldName != null) { var lookupValue = new Array(); lookupValue[0] = new Object(); lookupValue[0].id = id; lookupValue[0].name = name; lookupValue[0].entityType = entityType; Xrm.Page.getAttribute(fieldName).setValue(lookupValue); } }