iframe onSave Events in MS CRm 2011


//1.Save record embedded in iframe

//Account form with iframe, that displays contact form. Requirement is that when user press “save” button on account form, contact in iframe should be also saved.

var iframeXrmPage = Xrm.Page.getControl(“IFRAME_contact”).getObject().contentWindow.contentIFrame.Xrm.Page;

// 2. Suppose this is our custom entity named “new_mycustomentity” and we would like to show it in inside iframe within a custom aspx page.

//Users can create the new record from within the custom page.

//So we set the Iframe src to the url for creating new my custom entity record i.e.

//<iframe id=”IFRAME_NEWCUSTOMENTITY” frameborder=”0″ runat=”server”
//src = “http://localhost/Contoso/main.aspx?etn=new_mycustomentity&pagetype=entityrecord&#8221; & gt;

//However this is how it appears within in IFrame with no ribbons in it.

//So the next step would be to hide the blank space on the top as well as left navigation bar.Now we can use the following JavaScript that will hide the left navigation pane and blank ribbon.http://bingsoft.wordpress.com/2010/09/09/mscrm-2011-hide-areas-of-a-form/
function HideArea() {
// Hide the Ribbon Toolbar and move the form Content area to the top of the window

window.parent.document.getElementById(“crmTopBar”).style.display = “none”;

window.parent.document.getElementById(“crmContentPanel”).style.top = “0px”;
// Move Form Content area up to top of window, initial style.top is 135px
// set it to the height of the iframe

window.parent.document.getElementById(‘contentIFrame’).style.height = “400px”;

// Hide Left Hand Nav bar / pane
document.getElementById(“crmNavBar”).parentElement.style.display = “none”;
document.getElementById(“tdAreas”).parentElement.parentElement.parentElement.parentElement.colSpan = 2;
// Hide the Form Footer Bar
document.getElementById(“crmFormFooter”).parentElement.style.display = “none”;


// 3. How do I Validate with OnChange?

//Luckily this isn’t really that big of a deal. There are several options and its really whatever is best for you.

//Option 1: Blank the field.

//By far the easiest option is to just clear the field after prompting the user. The only downside is the user has to re-enter all of the data again.

function example(obj){
var rgCell = /[0-9]{3}-[0-9]{3}-[0-9]{4}/;
var sVal = obj.getEventSource().getValue();

if (rgCell.test(sVal)) {
// valid

} else {
// Invalid phone number
alert(‘Please enter a valid phone number (ex. 123-123-1234).’);


//Option 2: Utilize the OnSave

//There is a little more effort involved here, but a better experience for the user.

function example(obj){
var rgCell = /[0-9]{3}-[0-9]{3}-[0-9]{4}/;
var sVal = Xrm.Page.getAttribute(“mobilephone”).getValue(); //obj.getEventSource().getValue();

if (rgCell.test(sVal)) {
// valid
} else {
// Invalid phone number
alert(‘Please enter a valid phone number (ex. 123-123-1234).’);
Xrm.Page.getAttribute(“mobilephone”).controls.get(0).setFocus(); // only fires onSave

if (obj.getEventArgs() != null)





Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s