Working with CRM Forms in IFrame in CRM 2011

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”&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”;
}

Now the form looks like this within the IFrame

Next we will add an iframe in the entity’s form that will display a custom html page which has a Save Button in it to save the record.

However here we need to set the src of the IFrame dynamically through JavaScript in the form load otherwise our IFrame page won’t appear in the form.
So in form’s onload event add the following line

// set the IFrame src through JavaScript

crmForm.all.IFRAME_SAVE.src = http://server:port/CustomCRMPage/SavePage.htm&#8221;; 

This is how our custom page will now

 On the save button click add the following Jscript code to save the record.

<input
id=”btnSave” type=”button” value=”Save” onclick=”return Save()”
/>

function Save() {
// call crmForm.Save
parent.document.forms[0].Save();
}

Now let’s click on save and try to save the record,

 The record gets saved but here we can see two issues.

The top bar still shows “My Custom Entity – New” there.

And value for Owner field shows blank.

So here first we need to remove the Top Bar from the form using the following jScript in form’s onload

// hide the top bar

document.getElementById(“recordSetToolBar”).parentElement.parentElement.parentElement.parentElement.parentElement.parentElement.parentElement.parentElement.parentElement.parentElement.parentElement.style.display = “none”;

Now for the owner field ( lookup) we will have to do the following workaround.

Create a text field on the form, on save of form assign the Owner lookup’s name value to it. Hide this text field in the form onload.

Now in the onload event of the check if crmForm.ObjectId is null or not.

If not null than set the value of name for the owner’s lookup to this new hidden field’s value.

In form’s on save event à

function setOwner() {

var lookupItem = new Array;

lookupItem = crmForm.all.ownerid.DataValue;
// set the owner name in a separated text field
crmForm.all.new_hf.DataValue = lookupItem[0].name;
}

 And in the onload do the following à

if (crmForm.ObjectId != null) {

var lookupItemOwner = new Array;

lookupItemOwner = crmForm.all.ownerid.DataValue;
var lookupData = new Array();
//Create an Object add to the array.
var lookupItem = new Object();
//Set the id, typename, and name properties to the object.
lookupItem.id = lookupItemOwner[0].id;
lookupItem.typename = lookupItemOwner[0].typename;
lookupItem.name = crmForm.all.new_hf.DataValue;
// Add the object to the array.
lookupData[0] = lookupItem;
// Set the value of the lookup field to the value of the array.
crmForm.all.ownerid.DataValue = lookupData;

 }

Hope this helps …


Author: Nishant Rana

I love working in and sharing everything about Microsoft.NET technology !

27 thoughts on “Working with CRM Forms in IFrame in CRM 2011”

  1. Definitely believe that that you stated. Your favourite justification appeared
    to be on the web tthe easiest factor to underswtand of.
    I say to you, I definitely get annoyed whilst other folks think about concerns that they
    just don’t realize about. You managed to hit the nail upon thhe highest as smartly as outlined out the entire thing
    with no need side effect , folks could take a signal.
    Will likely be again to get more. Thanks

    Like

  2. Since most people on the planet are regular users of a car,
    the fun of train travel is unfamiliar to most. Thus, if you
    have frequent business trips, consider investing in a travel
    suitcase. There are some other tips and tricks that can be helpful for you to conceive a baby boy, but these tips are probably some of
    the best and they can actually aid you to increase your odds to conceive a boy, especially if
    you’ll use them together with each other.

    Like

  3. Good day! This is kind of off topic but I need some guidance from
    an established blog. Is it tough to set up your own blog?

    I’m not very techincal but I can figure things out pretty quick.

    I’m thinking about setting up my own but I’m not sure
    where to begin. Do you have any points or suggestions? Appreciate it

    Like

  4. It is continually great to fill your day with enjoyment as this Sunday Night Football Live Stream starts
    the stages today. Your current laptop can stream live tv displays provided
    that it has speeds of better than 400 MHz together with
    a virtual memory of about 500mb. This workweek’s apps are football-themed games for respective months in the Super Bowl.

    Like

  5. Hello there, I discovered your blog by way of Google even as searching for
    a comparable matter, your site came up, it seems great. I’ve bookmarked it in my google bookmarks.
    Hello there, simply become aware of your weblog thru Google, and located that it’s
    really informative. I am going to be careful for brussels.
    I will appreciate for those who continue this in future. Many other folks can be benefited from your writing.
    Cheers!

    Like

  6. Under federal law, marijuana use is still illegal even if some states have actually legalized
    medical marijuana. Reinhardt questions the assumptions made in formulating the Ohio estimates, and suggests the Lieutenant
    Governor may be providing Ohioans with misleading figures for political reasons.

    You will lose money for repairing the vehicle or even replacing it with another
    vehicle.

    Like

  7. I feel that is among the most significant info for me.
    And i’m glad studying your article. However wanna commentary on few normal issues, The web site style is wonderful, the articles is truly great : D. Excellent job, cheers

    Like

  8. Good day! Would you mind if I share your blog with my twitter group?
    There’s a lot of folks that I think would really appreciate your content. Please let me know. Thank you

    Like

  9. The usage of these two valves is that it is put on the hot air generators
    in four different ways. This handheld vaporizer is a heavy-duty portable vaporizer which catches everyone
    fancy. When you are looking at shopping for those who “medicate”, the medication itself is always a welcomed stocking stuffer.

    Like

  10. Another very big part of Zynga is their poker series;
    Poker Blitz, and Zynga Poker. Although Zynga has a good relationship with Facebook and generates 12% of
    that company’s revenue, Zynga is now looking to diversify its sources of income. That’s
    why it is really significant to often continue
    to keep up with new and helpful strategies, tricks and secrets.

    Like

  11. It was the comedy, however, which beat the destruction movie.
    Using pictures and other clips from the Minions, Minion Me 2 is an unofficial “Despicable Me” game , but still
    has some nice surprises. The Dukes was a victim of
    bad timing (its two biggest stars walking out just before production) and was a
    prime example of Hanna-Barbera’s animation factory at its worst.

    Like

  12. I recently had a first hand look at Angler’s Club: Ultimate Bass Fishing 3D, the first fishing game to take full advantage of the 3D capabilities of the Nintendo 3DS. This is by far the most annoying thing I have ever experienced in the game (besides crashes). There are 3 levels of the Garden Badge: Bronze, Silver, and Gold being the highest.

    Like

  13. Wonderful blog! I found it while surfing
    around on Yahoo News. Do you have any tips on how to get
    listed in Yahoo News? I’ve been trying for a while but I never seem to get there! Appreciate it

    Like

  14. The addition of an iOS application in your virtual marketing arsenal will help you in targeting your customers with a better approach and in a scalable manner.
    They provide a nice tactile feel and make it easy to find ‘home’ on the keyboard.

    If you are a glad consumer of Sprint, then you might most surely
    find their Sprint Loved ones Locator a fantastic instrument for keeping your
    partner’s mobile phone tracked.

    Like

  15. As a writer of goal achievement books, I have to love that kind of show.
    Its flexibility features makes you move around the house freely and easily.
    Or be prepared to pay a professional PR person to do it for you.

    Like

  16. Hi, I am Harish Kumar Gola working on CRM 2011, I tried to access CRM Account Entity in HTML Iframe of custom aspx page but it’s showing some javascript error, please let me know the solution if any…Thanks in advance.

    Like

  17. I am new to all of this and trying to move my url to the left, it would be easier to just copy and paste the correct code. If you showed the entire code for the page then I could easily cut and paste only the parts that I need. I really appreciate you providing this info.

    Like

Share your thoughts

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 )

Twitter picture

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

Facebook photo

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

Google+ photo

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

Connecting to %s