All code can be used to save time in adding funtionality to CRM.All Code published on this post is for use at your own risk.MSCRMER will not be held responsible in any way for any errors or system failures by using the code provided. Code formatting might be affected by table size.
==========
IFrames
//Contacts IFrame
function GetFrameSource(tabSet)
{
if (crmForm.ObjectId != null)
{
var oId = crmForm.ObjectId;
var oType = crmForm.ObjectTypeCode;
var security = crmFormSubmit.crmFormSubmitSecurity.value;
return "areas.aspx?oId=" + oId + "&oType=" + oType + "&security=" + security + "&tabSet=" + tabSet;
}
else
{
return "about:blank";
}
}
crmForm.all.IFRAME_Contacts.src = GetFrameSource("areaContacts");
=========
Custom Related Entities in a IFRAME
I used this code to have 5 iframes to related custom entities on a CRM form:Replace The (*) with your field and relationship names.
//OnLoad - JavaScript - (placed into the entity you want an iframe in)
function GetFrameSource(tabSet) {
if (crmForm.ObjectId != null) {
var oId = crmForm.ObjectId;
var oType = crmForm.ObjectTypeCode;
var security = crmFormSubmit.crmFormSubmitSecurity.value;
return "/userdefined/areas.aspx?oId=" + oId + "&oType=" + oType + "&security=" + security + "&tabSet=" + tabSet;
}
else {
return "about:blank";
}}
//Iframe 1
crmForm.all.IFRAME_*.src = GetFrameSource("*Unique relationship name*");
//Iframe 2
crmForm.all.IFRAME_*.src = GetFrameSource("*Unique relationship name*");
//Iframe 3
crmForm.all.IFRAME_*.src = GetFrameSource("*Unique relationship name*");
//Iframe 4
crmForm.all.IFRAME_*.src = GetFrameSource("*Unique relationship name*");
//Iframe 5;
crmForm.all.IFRAME_*.src = GetFrameSource("*Unique relationship name*");
========
Maximize your CRM Screens
if (window.screen)
{
var aw = screen.availWidth;
var ah = screen.availHeight;
window.moveTo(0, 0);
window.resizeTo(aw, ah);
}
==========
Confirm Save
if (confirm("Are you sure you want to save this form?"))
{
}
else
{
event.returnValue = false;
validationErrors = true;
}
==========
Making a field Read-Only
Copy this code in the onload on the crm form.
crmForm.all.*fieldname*.readOnly=true
==========
Autofill other dates form a selected date
This is very usefil if for example if you have and entity like contracts and depending on the date slected for "Start date" other date fields are updated.Copy this code to the respective field ,change event.
function dateAddExtention(p_Interval, p_Number)
{
var thing = new String();
p_Interval = p_Interval.toLowerCase();
if(isNaN(p_Number))
{
throw "The second parameter must be a number. \n You passed: " + p_Number;
return false;
}
p_Number = new Number(p_Number);
switch(p_Interval.toLowerCase())
{
case "yyyy": {// year this.setFullYear(this.getFullYear() + p_Number);
break;
}
case "q":
{
// quarter this.setMonth(this.getMonth() + (p_Number*3));
break;
}
case "m":
{
// month this.setMonth(this.getMonth() + p_Number);
break;
}
case "y":// day of year case "d":
// day case "w":
{
// weekday this.setDate(this.getDate() + p_Number);
break;
}
case "ww": {
// week of year this.setDate(this.getDate() + (p_Number*7));
break;
}
case "h":
{
// hour this.setHours(this.getHours() + p_Number);
break;
}
case "n":
{
// minute this.setMinutes(this.getMinutes() + p_Number);
break;
}
case "s":
{
// second this.setSeconds(this.getSeconds() + p_Number);
break;
}
case "ms": { // second this.setMilliseconds(this.getMilliseconds() + p_Number);
break;
}
default: { throw "The first parameter must be a string from this list: \n" + "yyyy, q, m, y, d, w, ww, h, n, s, or ms. You passed: " + p_Interval; return false;
}
}
return this;
}
Date.prototype.dateAdd = dateAddExtention;
var expireson= new Date(crmForm.all.activeon.DataValue );
var *new_increasedate*= new Date(crmForm.all.activeon.DataValue );
//CONTRACT EXPIRES ON 60 MONTHS FROM START DATE
expireson.dateAdd("m",60);
//RENEWAL DATE IS 55 MONTHS FORM START DATE
*new_increasedate*.dateAdd("m",55);
crmForm.all.expireson.DataValue = expireson;
crmForm.all.new_increasedate.DataValue = new_increasedate;
crmForm.all.billingendon.DataValue = expireson;
crmForm.all.billingstarton.DataValue = crmForm.all.activeon.DataValue;
===========