6.09.2006

Showing Associated Activities In An IFrame

Here's a cool little piece of script that can help make you a star for your customers/end-users. I frequently get the request to show history items right on the main tab of a CRM contact or an account form. A lot of salespeople are accustomed to other contact management solutions that don't require so much clicking around as Microsoft CRM.

So here's how you do it:
First, let's add an IFrame to your contact form. Let's call it HistoryFrame. Set the URL to "about:blank" (no http or anything), check the "Pass record object-type code and unique identifier as parameters" option, deselect the "Restrict cross-frame scripting." I've formatted my IFrame to automatically expand and scroll as necessary.


(Click image to enlarge)

We're going to add some script to the OnLoad event to dynamically change the URL of the IFrame to point to the activities history. In addition, we're going to remove the History link from the left navigation, just to unclutter the view for our end-users and so they're not confused ;-)

Next, on the contact form customization screen, click Form Properties and choose the OnLoad event and click Edit.

Add this script and enable it:

var navActivityHistory;
navActivityHistory =
document.all.navActivityHistory;

if (navActivityHistory != null)
{
navActivityHistory.style.display = "none";
document.all.IFRAME_HistoryFrame.src="/sfa/conts/areas.aspx?oId=" +
crmForm.ObjectId +
"&oType=2&security=852023&tabSet=areaActivityHistory";
}
else
{
alert("navHistory Not Found");
}
The key part of this script is the tabSet=areaActivityHistory part. If you want to show the open Activities in the IFrame, the tabSet will be areaActivities and you will want to change the navActivityHistory to navActivities in the rest of the code.

Here's the finished product:


(Click image to enlarge)

Now, if you can figure out what the other tabSets are called in a MS CRM record, you can go IFrame crazy!

Hope you find this helpful. If you do, give the ads a click! Thanks!

122 comments:

Anonymous said...

I think this string:
navActivityHistory.style.display = "none";

will be much better if we do like this:
crmForm.all.navActivityHistory.removeNode(true);

If we do that, we don`t see a white space=))

p/s
maybe you know what mean parameter
security=852023 ??

Matt Wittemann said...

Thanks for the tip. I'll give it a try, but I didn't get any white space with the code I used...

Not sure what the security parameter means. Anyone have some insight?

Anonymous said...

real nice as i have ex-ACT clients that wanted a similar look.

But, when we create a new Contact record the form loads with an error in the Iframe until it is saved.

Have I done something incorrectly?

Jerry

Matt Wittemann said...

You need to add a check to your script to see if the form is a Create form or an Update form. Something like:

if (crmForm.FormType == 1)
{
document.all.IFRAME_HistoryFrame.src="about:blank";
}
else
{
the rest of the script;
}

Check the SDK for info on the form types.

Matt Wittemann said...

Found this on one of the newsgroups about the security parameter. This is from a developer within MS:

"It is used as a hint, to determine which UI elements to render out. For example, if you do not have permissions to Assign, then the button is not rendered out. Note that the actual security checks, as you would expect, do NOT simply trust this value. If a user were to change this value to include Assign privileges, (s)he would see an Assign button, but would get an Insufficient permissions error when clicking on the button."

Anonymous said...

Would it be possible to list the activities from the sub-accounts also?

Matt Wittemann said...

The default view of activities in associated views includes "Related Records," which should include sub-contacts and sub-accounts, etc.

Anonymous said...

I'd love to do this with "accounts". I tried copying pasting the code, and I get an error stating the the IFrame is Null or Not an object. I also tried changing "/sfa/conts/..." to "/sfa/accts/..." (after referring to the folder structure under inetpub) with no success. Ideas?

Thanks for the great tip!

Andy

Anonymous said...

Hello!

Could I do this with quoted products also?

Anonymous said...

Does this only work with system entities? I can make is work for activity, history, relationships, etc. But any custom entity I've created and appears in my left nav won't seem to work.

Anonymous said...

Brilliant creative thinking here, as this eliminates the need for ISV solutions.

Hint: if you want to be able to change the view while looking at the detail records, you will need to add some code top the on change as well.

Matt Wittemann said...

Thanks for the nice comments. I'm not clear on what you mean about changing the view while looking at the detail records. Can you elaborate on this?

Anonymous said...

I had to add the &refresh=true to get the control to display activities upon reload..

Anonymous said...

I now have this working in the OnLoad of my entity and have discovered in the Entity Viewer how to manually find the oType (Object Type Code). It works great. However, I need to be able to promote these configurations through Dev and QA environments which will have a different Object Type Code for the entity.

Is there a way in the onLoad JavaScript to determine the Object Type Code of the entity?

Thanks!

Anonymous said...

I just posted the last anonymous question and forgot a very valuable hint I discovered. You should rap your entire onload script in a conditional to ensure that your crmForm.formType is Update rather than create. Your iFrame will error out if you are creating a new record. You may also need to hide it if formType = 5, which is the quick create.

Anonymous said...

Can't someone tell, how we can get those tabsets?
That would really help out!

Matt Wittemann said...

Download the Internet Explorer Developers Toolbar from microsoft.com. It's an add-in to IE that lets you analyze webpages. It will let you break apart the CRM forms and find the names of those tabsets.

Anonymous said...

var navExistingProducts;
navExistingProducts =
document.all.navExistingProducts;

if (navExistingProducts != null)
{
navExistingProducts.style.display = "none";
document.all.IFRAME_existingFrame.src="/sfa/salesorder/areas.aspx?
oId=" +
crmForm.ObjectId +
"&oType=2&security=852023&tabSet=areaexistingproducts";
}
else
{
alert("navExisting Products Not Found");
}

I have this script in my order form, but it does nothing. What am I doing wrong?

Anonymous said...

Check that your oType is correct. Or just use this code so it is always correct:

+ "&oType=" + crmForm.ObjectTypeCode

Also, you might take it out of the if conditional just to check if you if statement is correct.

The the question in the previosu post, in CRM view an instance of the entity you wish to add such an iFrame to. Click 'ctrl N'. This will launch the view in a full browser window. Then view the source and search for 'LoadArea'. Each left nav item will have one.

-Temple

Anonymous said...

MattNC,

I have the frames working, and they are absolutly great, but i have a problem with my custom made entity. I think the problem is in "document.all.IFRAME_dongleframe.src="/userdefined/areas.aspx?oId=" The userdefined part, i believe this has to be something else, but i don't know what. Here is the whole code;
var nav_new_dongle_contracts;
nav_new_dongle_contracts =
document.all.nav_new_dongle_contracts;

if (nav_new_dongle_contracts != null)
{
nav_new_dongle_contracts.style.display = "none";
document.all.IFRAME_dongleframe.src="/userdefined/areas.aspx?oId=" +
crmForm.ObjectId +
"&oType=1088&security=852023&tabSet=new_dongle_contracts";
}
else
{
alert("nav_new_dongle_contracts Not Found");
}

Anonymous said...

To find the right source, open a CRM view in which your custom entity appears in the left nav. Hit Cntrl N. This will open it in a new browser. View the HTML. Search for 'LoadArea' and find the load area for the entity you are looking for.

-Temple

Matt Wittemann said...

The associated view of activities for cases doesn't have the "Filter On" and "Include" dropdowns as it does for contacts or accounts. If you look at the Activities on a case before enabling this OnLoad script, you will see that this is standard out of the box.

Anonymous said...

Thanks for the post, my (former ACT) users love it! One question... even when the "Related Records" filter is selected, I'm only getting activities from the parent account, and not any of the Contacts on that account. Is there a way to also list the activites related to the Contacts owned by the Account?

Anonymous said...

I believe the problem lies in the userdefined part. If you make a new entity yourself. The path is always is userdefined (src="/userdefined/). Salesorders is this (src="/sfa/salesorder), but a custom entity is always userdefined. So what do I fill in, because filling in userdefined does not work.

Anonymous said...

With this setup should the user be able to create a new activity from the IFrame? So far whenever I create an IFrame we are unable to link from the IFrame. For example, I have created an IFrame linking back to SharePoint, but we are unable to open files from SharePoint.
Thanks

Matt Wittemann said...

That sounds like two questions. If you show the history of a contact in an iFrame, you should be able to click the icon on the top of the history list to create a new activity.

If you are showing a SharePoint webpart or webpage in your iFrame, and it is not functioning as expected, that would be a different problem. With SharePoint, I would suspect that there might be a script conflict or authentication issue.

Anonymous said...

This is pretty cool... do you have any ideas on how to use this functionality to display Notes, as opposed to Activities? Thanks!

Mark

Matt Wittemann said...

Notes in CRM 3.0 are in a special section on the form (cases, contacts, accounts, etc.). The whole notes section can actually be moved wherever you want it, just like moving any other section around on the form. In the form customization area, just double click a blank area in the notes section and you will open a dialog that lets you choose which tab you want to move it to.

Anonymous said...

I enountered a little problem not mentioned here. I use this great tip to fetch a few query-pages from our intranet, based upon a parameter in a custom field "Project Code". But my users don't always enter proper project codes. These should start with "P" but they sometimes enter something like "various" or "dunno". I want to do a simple check that the first character is a "P" in order to avoid errors in the script (so if it doesn't start with "P" I show them abou":blank).
BUT : I can't seem to address the first character. Substring() does not work, neither does projectcode[1] or even the (string) typecast. Does CRM use proper C#? Does anybody know a trick that works?

Ron

Matt Wittemann said...

How about using some script in the field itself to alert the user when they enter "dunno" -- use an OnChange event to put up an alert "Project Code must start with 'P'"---and the SDK will show you some good examples of script you can use for iFrames, etc. You need to use jscript not C# in field and iFrame properties.

Anonymous said...

thanks for this tip. I find it really useful, but unfortunatelly I am not able to display any custommade entity this way :(. Do you have any idea way? I can display the view of any system entity, so I think I understand the code... but...
Did you manage to display the custom entity on the tab? How

Matt Wittemann said...

The URL should be http://crmserver/SFA/conts/areas.aspx and make sure to replace crmserver with the address of your server.

Anonymous said...

I am trying to display a custom entity on a tab on the contact entity form in an IFrame. I can display the custom form but am having trouble getting the objectId of the contact to append to the src. Ex. document.all.IFRAME_TestInfo.src="/UserDefined/edit.aspx?etc=10002" + "oId="+crmForm.ObjectId +"&oType=112&security=852023&tabSet=contact_new_info"; When I include the oId=..., the iframe shows an error page. If I leave it out, I get a blank editable form. What is the correct syntax to get the ID to use to display the custom entity that is associated with the Contact?

Thanks

Anonymous said...

I am trying to display a custom entity on a tab on the contact entity form in an IFrame. I can display the custom form but am having trouble getting the objectId of the contact to append to the src. Ex. document.all.IFRAME_TestInfo.src="/UserDefined/edit.aspx?etc=10002" + "oId="+crmForm.ObjectId +"&oType=112&security=852023&tabSet=contact_new_info"; When I include the oId=..., the iframe displays an error page. If I leave it out, I get an editable form. What is the correct syntax to get the Id that is associated with the contact in the src line?
Thanks

Anonymous said...

I found the problem. I can get the objectid now. However, I need to get the GUID of a custom entity to use as the id to display on the tab on the COntact form. I am new to CRM but I am pretty sure I need to perform a callout to retrieve the GUID from the custom entity. Can this be done through javascript?

Anonymous said...

This idea works great all over the place thanks!
one issue is when my users goto print the page the IFRAME shows "navigation to this webpage has been canceled"

any ideas?

thanks

Anonymous said...

Hi,

Great bit of code, always nice to stumble across a useful feature.

I have a problem though - the history shown in the IFrame does not include "Quote Closed" or "Opportunity Closed" activities. These show up under the normal history link.

Any ideas on resolving this would be much appreciated.

Anonymous said...

when I use this Iframe to enter activites, it is not showing up activities in that screen. If I refresh the screen then only activity is showing up in the Iframe.

any solution for that.....

Anonymous said...

I have the same problem as some other people... The activity history is always empty, even after a refresh. Someone suggested a refresh command, but I have no idea where to put it since I'm a zero on scripting ;)

Anonymous said...

Taking a clue from your 1st post, i tried hiding other entities like Opportunities, Contracts, Marketing etc from the Contact form on the On load event... Can you post the sample script for this?

Anonymous said...

How can i get "Notes" in side an iFrame? Any help-idea will be apprecaited.

Matt Wittemann said...

I'm not sure why you would want to show notes in an iframe. You can move the Notes section to any tab on the form by going to Settings > Customizations and editing the form.

Anonymous said...

Thnks for the reply but the client want 4 notes on all 4 tabs. Is that possible?

Matt Wittemann said...

You can not add four different Notes sections to a record, since it is not possible to have a one-to-many relationship in CRM 3.0. I can't think of a way to display the same Notes section on multiple tabs. Sorry!

Tushar Roy said...

Hi All,

I'm trying to remove scrollbars from the Iframe I created, but nothing like the following seem to work:

-document.getElementById('IFRAME_new').style.overflow = 'hidden';
-crmForm.all.IFRAME_new.style.overflow = 'none';
-crmForm.all.IFRAME_new.setAttribute("style", "overflow:hidden");

Thanks in advance.

Matt Wittemann said...

You control scrolling on an iframe in CRM via the form customization. Open the form editor and double-click the iframe to view its properties. Click on the "Formatting" tab and near the bottom is a Scrolling setting.

Al Pemberton said...

We are using C360 for duplicate checking. When I setup the IFRAME as you layed it out the C360 removes the new code every time I publish. Any ideas on how to get around this?

Al

Anonymous said...

I've been using this iFrame solution and love it. But I have noticed that when you do a print from the parent page, the iFrame shows in the printout with an 'Action Canceled' error instead of showing the content of the iFrame. Has anyone gotten Print to work on a screen with an iFrame?

Anonymous said...

It seems as though there is no onLoad script executed when the print function is used. It simply displays the origional form. So, in this case, where we are dynamically generating the URL for this iFrame based on the objectid in the onLoad event, it will not print correctly. You could, however, write a static page and use that rather than the "about:blank" so that when you printed it would look a little cleaner.

Anonymous said...

I am trying to add the Incidents information to my iFrame. I don't really know what I am doing is there anyone who can help me? By the way I renamed Incidents to Exchanges.

Anonymous said...

How does one reference the Relationship subarea into the iframe? I have gotten the activities and even other custom related entities, but i can't seem to get the relationship. here is my code (this is on the opportunity entity):

//Relationship iframe
var navRelationship;
navRelationship=
document.all.navRelationship;

if (navRelationship != null)
{
//navRelationship.style.display = "none";
document.all.IFRAME_relation.src="/sfa/conts/areas.aspx?oId=" + crmForm.ObjectId + "&oType=" + crmForm.ObjectTypeCode + "&security=852023&tabSet=areaRelationship";
}
else
{
alert("navRelationship Not Found");
}

I just modified your code, so it should be easy, but it is not working.
Thanks in advance!

Anonymous said...

I just posted, and I realized that I needed to pluralize the areaRelationshipS, but this brings a new problem. it is showing a generic relationship iframe, not the one specific towards this opportunity. I want it to show all of the relationships to/from this opportunity in the iframe...what do you suggest that I do?

Thanks!

Matt Wittemann said...

You've almost got it. I think you just need to change "areaRelationship" and "navRelationship" to "areaRelationships" and "navRelationships" with an 's' on the end. I think that will do it for you...

Anonymous said...

Matt,

I don't know if you saw the second post I posted...but when you reference the areaRelationships, it simply shows an iframe of the generic Customer Relationships, not the opportunity specific relationships...how would you suggest that I proceed in order to do this? I will work on it and post a sln if I come across one before you post. Thanks.

Benjamin Rutledge said...

Matt,

What if I didn't want to display one of the NavBar elements in the iFrame? What if, instead, I wanted to show the contact update form for a contact.GUID from a lookup field in the main body of the form? How would I modify your code to make it work?

Please advise.

Thank you,
Benjamin

Anonymous said...

Hola, wherefrom I can extract the information of security this parameter

Anonymous said...

In order to get it working for a custom entity you need to specify the url as userdefined/areas.aspx?oId=" and set the type to the parent entity. They start on 10000 and go upwards...

Good luck!

Atilio said...

mm, for example in this URL

document.all.IFRAME_existingFrame.src= " /sfa/salesorder/areas.aspx? oId= " + crmForm.ObjectId + “&oType=2&security=852023&tabSet=areaexistingproducts

like that the parameter security is 852023? . thx

Anonymous said...

I love the posting! Now I'm trying to figure out if I can use this to solve my problem. Outlook users can see the To/From parties of an e-mail, but this does not show in History. I was going to work on a View to try to display this data with the direction. Is it possible to show the results of the custom View in an I-frame? The Users are having a hard time adjusting to the History View of CRM.
Also the date field is the date/time that the e-mail is promoted, not actually sent from Outlook - true? Is there anyway to bring that data into CRM when the e-mail is promoted? Can we map fields from Outlook's e-mail to History?
Thanks for all of your hard work!

Anonymous said...

Very useful script. Thanks.

I noticed that someone else asked how to add multiple notes pages to the form. This can be done by again adding IFrames and setting the URL to:

'/_controls/notes/notesdata.aspx?id=' + crmForm.ObjectId + '&ParentEntity=' + crmForm.ObjectTypeCode + '&NotesView=1&EnableInlineEdit=true&EnableInsert=true&refresh=true';

The main problem you will encounter is that when you add notes to one it won't be reflected in the others until you reload/refresh the page.

Anonymous said...

Does any one know of a way to combine the data from the history tab and the activities tab and display it into a single Iframe on the screen?

Anonymous said...

I'm the one that requested To/From parties in History for E-mail -- I never figured that out, but is it possible to display a Saved View in an I-Frame? How would I figure out what the Saved View is called? I could use the Advanced Find for All E-mails of Current User and then display that in the I-frame. The other option would be to create a SQL statement with the values I want to display...then I guess I create a SRS Report. Any words of advice? Marty

Matt Wittemann said...

Even if you could find the URL of a Saved View, it wouldn't be context sensitive to the particular Contact or Account you were looking at. You could put a SQL report in an iframe and pass the contactid to it. That might be your best bet.

Ramzi MOUELHI said...

Ability to change filter in DETAILS Activity or History view.
In various Record views (i.e., Account, Contact, Lead, etc.), when using the
DETAILS view for Activites or History, it would be nice to have the ability
for the user to change the filter default time frame from 30 days to another
setting. That way the user would not have to change the filter each time a
record's Activities or History would be viewed, to something other than 30
days.

Nick Doelman said...

Hi

There seems to be a popular post. I am implementing CRM at a company replacing Telemagic, so I have embedded the contact associated view in an iframe of the account form using this method. (Replicating the telemagic company screen) However, when any user selects "new contact", big CRM error message pops up, add related and regular methods still work. Anyone try this and does anyone have any resolution?

thanks
Nick

Matt Wittemann said...
This comment has been removed by the author.
Matt Wittemann said...

The fourth comment on this post has script that will check to see if the form is a "create" form instead of an update. If it's a create form, it will change the iframe to display a blank page.

Nick Doelman said...

I just left a post indicating the the "new contact" button caused and error, I must have been using the wrong objecttype because adding this line:

+ "&oType=" + crmForm.ObjectTypeCode

resolved the issue.

This piece of code is awesome!

Thanks
Nick

Stephaner said...

This is fantastic!!! I actually ended up adding a Pending & History tab to our Acct & Conts entities with the IFrames within each and everyone just loves it. Now I'm trying to figure out how to do the same with Cases but am having problems. Here's what I did...I may be totally off but what can I say. Any help would be appreciated!!! Thanks

//CASES
var navCases;
navCases =
document.all.navCases;

if (navCases != null)
{document.all.IFRAME_Cases.src="/sfa/accts/areas.aspx?oId=" +
crmForm.ObjectId +
"&oType=2&security=852023&tabSet=areaCases";
}
else
{
alert("navCases Not Found");
}

Unknown said...

Hi,

Actually this article is fine.
But, i have a problem in Iframe, can any one help to solve.

Here my problem is, i have placed one Iframe in CRM Phone Call Activity form. Now i want to refresh that IFrame alone for every 2 seconds to get latest events from server and to display in IFrame.

I tried but i can refresh the entire page not particular IFrame.

Please any one help 2 solve this soon.

Anonymous said...

I need to display an iframe on the account entity that shows campaign activities associated to that account. Any idea how this could be done?

Anonymous said...

This is great, how do i resize an iframe in case i have used it to display a photo. that will solve my other problem.

Anonymous said...

Hi Matt
Is it possible to resize an iframe, say maybe you use it to display a photo and you want it to be the size of the photo/image. that will solve my problems as well. thanx

Anonymous said...

This is a great feature and I have used it a few times in different projects. However, I am still struggling with custom entities. I've made a custom entity called "rhk_events". The ObjectTypeCode = 10000, the loadarea name = contact_rhk_events and the Id = nav_contact_rhk_events. The IFRAME is called: IFRAME_EventsFrame. Below you will find the code. Can you help getting it to work correctly? Regards, René

if (crmForm.FormType == 1)

{
document.all.IFRAME_EventsFrame.src="about:blank";
}

else

var navEvents;
navEvents = document.all.nav_contact_rhk_events;

if (navEvents != null)

{
// nav_contact_rhk_events.style.display = "none";

document.all.IFRAME_EventsFrame.src="/UserDefined/areas.aspx?oId=" + crmForm.ObjectId + "&oType=2&security=852023&tabSet=areacontact_rhk_events";
}

else
{
alert("navEvents Not Found");
}
}

Anonymous said...

Try changing &oType=2 to &oType=1 like this:

//CASES
var navCases;
navCases =
document.all.navCases;

if (navCases != null)
{document.all.IFRAME_Cases.src="/sfa/accts/areas.aspx?oId=" +
crmForm.ObjectId +
"&oType=1&security=852023&tabSet=areaCases";
}
else
{
alert("navCases Not Found");
}

Anonymous said...

Rene,
Try
document.all.IFRAME_EventsFrame.src="/UserDefined/areas.aspx?oId=" + crmForm.ObjectId + "&oType=" +
crmFormSubmit.crmFormSubmitObjectType.value + "&security=" +
crmFormSubmit.crmFormSubmitSecurity.value; + "&tabSet=areacontact_rhk_events";

The only problem I am having with this is mine is a custom entity view going into a custom entity form annd the create button is not working in the view

Any Ideas on this???
Joe

Anonymous said...

Hi,
I want to display all activities(email,fax ...) of an incident in iframe. why this url failed to load

http://crmserver/UserDefined/areas.aspx?oId=9FCE3B7D-BB74-DC11-93B9-0003FFE39DE8&oType=112&security=852407&tabSet=incident_activitypointers

Unknown said...

Does someone know if you can remove the menu of the associated view once its displayed in the IFrame ?

Anonymous said...

how can this i frame be used to display a picture?

Anonymous said...

how do we dispaly a picture in the iframe?

Unknown said...

how can this i frame be used to display a picture?

I meant the menu where you can add new items or delete items ...

With delete access denied on the security role it can be done, but i want this to be possible through scripting.

Anonymous said...

I am working on custom entity to be displayed on iFrame for a long time but to no avail. Please sheer some light on these codes. The objecttypeid is 10003, the id is nav_new_ace_new_insurances and the LoadArea is new_ace_new_insurances. I've been changing alot of things to the following code but it is not helping. The iFrame still cannot be displayed.

document.all.IFRAME_Insurances.src="/UserDefined/edit.aspx?etc=10003" + "oId=" + crmForm.ObjectId + "&oType=112&security=852023&tabSet=new_ace_new_insurances";

Matt Wittemann said...

Try this:
document.all.IFRAME_Insurances.src="/UserDefined/edit.aspx?etc=10003?oId=" + crmForm.ObjectId + "&oType=112&security=852023&tabSet=new_ace_new_insurances";

Anonymous said...

tried that. It's still not working. The iFrame to be called is a custom entity, and I am actually doing this on a custom entity also. I've even tried this but not working too.

document.all.IFRAME_Insurances.src="/UserDefined/areas.aspx?oId=" + crmForm.ObjectId + "&oType=3&security=1&tabSet=new_ace_new_insurances";

Is there something that I've missed?

Anonymous said...

I have finally got the code running. Please refer to this if you are to do custom entity next time.

document.all.IFRAME_Insurances.src="/UserDefined/areas.aspx?oId=" + crmForm.ObjectId + "&oType=" + crmForm.ObjectTypeCode + "&security=852023&tabSet=new_ace_new_insurances";

Anonymous said...

I sure hope Matt or someone is reading this who can help me.

I spent an etire day trying to get this code to work for a client.

I created a custom entity called new_notes

I would like to show the view on the general tab of an account

here is my code. I double checked the ID and the load area and I cannot for the life of me get it to work.

When the iframe opens I get the following error:

Microsoft CRM Unhandled Error Details:
Server Error in '/' Application.
--------------------------------------------------------------------------------

Object reference not set to an instance of an object.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.

Source Error:

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

Stack Trace:


[NullReferenceException: Object reference not set to an instance of an object.]
Microsoft.Crm.Application.Controls.AppAreaPage.Render(HtmlTextWriter output) +68
System.Web.UI.Control.RenderControl(HtmlTextWriter writer) +243
System.Web.UI.Page.ProcessRequestMain() +1926



Here is my code

/* Code to add notes to general tab */

var QNotes;
QNotes = document.all.nav_account_new_notes;


if (QNotes != null)
{
QNotes.style.display = "none";

document.all.IFRAME_notes.src="/UserDefined/areas.aspx?oId=" + crmForm.ObjectId + "&oType=" + crmForm.ObjectTypeCode + "&security=852023&tabSet=areaaccount_new_notes";

}

else
{
alert("QNotes Not Found");
}

Silly said...

I have created the IFRAME and have the code on the onload event(Account), The problem is when I'm testing the code,nothing is displayed on the IFRAME,only the else statement is executed (new_projects not found). I have tried removing the if statement but still can't get it to work. Can anyone urgently assist me PLS.Am I missing out something.

Herewith is the code:

var new_project;
new_project =
document.all.new_project;

if (new_project != null)
{
new_project.style.display = "none";
document.all.IFRAME_Projects.src="/sfa/accts/areas.aspx?
oId=" +
crmForm.ObjectId +
"&oType=1&security=852023&tabSet=new_project";
}
else
{
alert("new_Project Not Found");
}

Anonymous said...

Are you using CRM 3.0 OR 4.0?

Anonymous said...

I'm using CRM 4.0

Anonymous said...

Hi Matt,

This is a great script but we have suffered an unfortunate side effect which we cannot reverse.

We created the iFRAME with the setting "automatically expand to use available space". The iFrame is on the same page as the Notes section.

This has now removed the expansion from the Notes section.

We moved the iFRAME to another tab but the Notes section is Locked and we can't reset the expansion for Notes which are now stuck in a small letterbox.

Do you know how we can reverse this?

David

Matt Wittemann said...

Try exporting the XML for the entity (make a backup copy of it) and locate the Notes node. Look for the row height tag in the Notes section and set it to auto:
<row height="auto" />

Then re-import the customizations.xml file for this entity and publish.

The usual caveat applies: Hand editing the XML is not a supported method of customization in most cases.

If the row height is already set to "auto" then there must be something else going on with your form. Even though you removed the iframe, did you leave an empty "Section" on the form?

Anonymous said...

Hi
I upgraded my server today to CRM 4.0, and suddenly my IFrames (showing associated contacts) doesn't work any more... "An Error has occured". Do you know what has changed in 4.0? Here's my old code (workes in 3.0):
contactsFrame.src="/sfa/accts/areas.aspx?oId= " +crmForm.ObejctId +"oType=" + crmForm.ObjectTypeCode + "&security=852023&tabSet=areaContacts&refresh=true";

/Kristine

Unknown said...

has anyone tried this method in CRM 4.0? Because it seems to me that the relative URL reference might not work as the url changes in CRM 4.0 now to include the company name.

Anonymous said...

Hi,
If anyone has found this in version 4.0 please help I couldnt get it to work.
Thanks.

Anonymous said...

I have found this from the newsgroup and it works in version 4.0

var CRM_FORM_TYPE_CREATE = 1;
var CRM_FORM_TYPE_UPDATE = 2;
var CRM_FORM_TYPE_READONLY = 3;
var CRM_FORM_TYPE_DISABLED = 4;
var CRM_FORM_TYPE_BULKEDIT = 6;
var CRM_FORM_TYPE_UNDEFINED = 0;
switch (crmForm.FormType)
{ case CRM_FORM_TYPE_UPDATE:
case CRM_FORM_TYPE_READONLY:
case CRM_FORM_TYPE_DISABLED:
document.all.IFRAME_Projects.src= "/userdefined/areas.aspx?oId="+
crmForm.ObjectId +
"&oType=" +
crmFormSubmit.crmFormSubmitObjectType.value +
"&security=" +
crmFormSubmit.crmFormSubmitSecurity.value +
"&tabSet=new_accounts_new_projects" ;
break;

case CRM_FORM_TYPE_CREATE:
case CRM_FORM_TYPE_BULKEDIT:
case CRM_FORM_TYPE_UNDEFINED:
document.all.IFRAME_Projects.src= "about:blank";
break;
}
Many Thanx.

Anonymous said...

Great script Matt. Thank you very much. This is exactly what we needed. But I did run into a problem and was wondering if anyone can help me. In our development server, we are running MSCRM 4.0. Here is the script we are running.


//**************************************
var navActivities;
navActivities =
document.all.navActivities;

if (navActivities != null)
{
navActivities.style.display = "none";
navActivityHistory = "none";
navAddresses.style.display = "none";
navAsyncOperations.style.display = "none";
navListsInSFA.style.display = "none";
navCampaignsInSFA.style.display = "none";


document.all.IFRAME_Activities2.src="/sfa
/conts/areas.aspx?oId=" +
crmForm.ObjectId +
"&oType=2&security=852023&tabSet=
areaActivities";
}
else
{
alert("navActivities Not Found");
}
//*******************************************



//*******************************************
var navActivityHistory;
navActivityHistory =
document.all.navActivityHistory;

if (navActivityHistory != null)
{
navActivityHistory.style.display = "none";


document.all.IFRAME_HistoryFrame2.src="/sfa
/conts/areas.aspx?oId=" +
crmForm.ObjectId +
"&oType=2&security=852023&tabSet=
areaActivityHistory";
}
else
{
alert("navHistory Not Found");
}

As you can see we have two iFrame script running. This was because we needed to see both the Activities and History. It works, as long as we Save and Close. For some strange reason, when we try just Saving it, the whole CRM locks up and I need to "End Task." If I comment out one of the codes, doesn't matter which one, it works great on Save and Save and Close.

Any help will be greatly appreciated. Thanks.

Matt Wittemann said...

I haven't tested it, but it looks like you need to separate the two clauses properly. I think you can use a "continue" statement. Try this:

{
//**************************************
var navActivities;
navActivities =
document.all.navActivities;

if (navActivities != null)
{
navActivities.style.display = "none";
navActivityHistory = "none";
navAddresses.style.display = "none";
navAsyncOperations.style.display = "none";
navListsInSFA.style.display = "none";
navCampaignsInSFA.style.display = "none";


document.all.IFRAME_Activities2.src="/sfa
/conts/areas.aspx?oId=" +
crmForm.ObjectId +
"&oType=2&security=852023&tabSet=
areaActivities";
}
else
{
alert("navActivities Not Found");
}
//*******************************************
}
continue;
{
//*******************************************
var navActivityHistory;
navActivityHistory =
document.all.navActivityHistory;

if (navActivityHistory != null)
{
navActivityHistory.style.display = "none";


document.all.IFRAME_HistoryFrame2.src="/sfa
/conts/areas.aspx?oId=" +
crmForm.ObjectId +
"&oType=2&security=852023&tabSet=
areaActivityHistory";
}
else
{
alert("navHistory Not Found");
}
}

Anonymous said...

Thanks for the quick reply Matt. I tested it out and when I added those codes, the jscript stops working. iFrame does not load and those fields on the left Nav bar appears.

Any other ideas? Thanks.

Anonymous said...

Hi Matt... I have read this entire post and seen all of the various uses and problems that people are having. I have one of my own that does not seem to be addressed.

I am using the IFRAME to display Opportunity Products on the front page of the related opportunity.

Works great, but my problem is
that when you add a NEW Opportuntiy Product, the IFRAME grid does not refresh, so the newly added record does not appear unless I manually refresh the grid. Strange, because with the traditional CRM screens, the grid refresh happens automatically when a new record is created. Can I programatically translate that same action to the IFRAME version of this same grid?

Anonymous said...

Matt, many thanks for the tip on fixing the Notes problem with the XML customisations. That worked perfectly!
Thanks

Unknown said...

We've been using this kind of modification in CRM 3.0 for awhile and it works fine in CRM 4.0....except when a user refreshes a form where this mod is called using onload. It seems that in CRM 4.0, the onload isn't called on refresh (F5), assumedly for performance reasons. (?)

Here's something I concocted today to resolve this. The following functions are declared for when a user refreshes a Contact form:
********
function frm_Contact_OnRefresh()
{
if (window.event)
{
document.onkeyup = testcontactrefresh;
document.onkeydown = testcontactrefresh;
}
document.onkeypress = testcontactrefresh;
}

function testcontactrefresh(e)
{
var keyId = (window.event) ? event.keyCode : e.keyCode;

if(keyId == 116)
{
frm_Contact_OnLoad();
if (window.event) event.keyCode = 0;
else keyId = 0;
return false;
}
}
********
I call frm_Contact_OnRefresh()
in the contact OnLoad first, then immediately call my frm_Contact_OnLoad() function, which contains all the javascript we want to use on loading (and refreshing!) a contact form. If anyone has comments or feedback on this refresh issue, please don't hesitate to respond because I'm only on day 2 of testing CRM 4.0 and this promises to be a LONG process!!

Anonymous said...

I have a client who wants something very similar to this - the ability to show the associated activites in an iFrame.
However, they only want to show activities of type 'phone call', and to show some extra fields that area in the phone call record (eg, phone number).
Is there a way to do this?

Mike Feingold

Anonymous said...

I am looking for the same functionality: I only want to show the related tasks of an account that have a specific type.

I thought of injecting the current account object id into a fetchxml clause (to create fetchxml see http://ronaldlemmen.blogspot.com/2006/11/using-advanced-find-for-fetchxml.html ) and display those results. This would work if you could pass a fetchxml string to an aspx page (I guess this happens when you press query in the advanced find view) Does this exist?

Anonymous said...

Hi,

I've added a new tab to MSCRM V4 with an iframe i use a java scriptto populate the src property and it loads as custom asp.net website, Tisall works wonderfully, howver I;m showing grids od data from an external data source, one of the columns is set as a hyperlink, whent he website is loaded in IE ths click through on the link appear in the same window, but when in the MSCRM v4 iframe the click throughs pop a new window no matter what the target property is set to or if i set thetarget to the name of the iframe.

Can anyone tell me why and how to stop it popping a new window?

Rich said...

All this works great until 4.0 - even then it works great unless you want to do this with a many to many relationship and then you get "invalid argument" messages.

Any ideas? If you look at the loadarea the # parms after the name of the load area have a lot more things in it than when it is just a 1 to many. I just don't know what they all mean!!

Laura and Lane said...

Hi!

We have this IFrame.

However, we can't seem to get the Activities to default to ALL with the IFrame without and error.

HELP!! :)

Anonymous said...

Hi, This is the first time I've tried to do an IFrame. I've added the IFrame to the contact form, copied the code in the On-Load event, enabled it, and published. When I open a contact record, I get the error "Navigation to the webpage was canceled". I am sure I am missing something very basic...but don't know what it is. Can anyone help? Thank you!

Chris Brown said...

Hello,

I am trying to show the Products in an IFrame inside Opportunities so that the users don't have to click on the side. I came across the following link which talks about showing Activities in the IFrame, but I can't get it to work. http://icu-mscrm.blogspot.com/2006/06/showing-associated-activities-in.html

The javascript that I am currently trying to use is below.

Any help would be much appreciated.

{
var navProducts;
navProducts = document.all.navProducts;

if (navProducts != null)
{
document.all.IFRAME_Products.src="/sfa/opps/edit.aspx?oId=" + crmForm.ObjectId + "&oType=" + crmForm.ObjectTypeCode + "&security=852023&tabSet=areaProducts";
}
else
{
alert("navProducts Not Found");
}
}

Unknown said...

Chris Brown --
I was having the same problems and was about to give up when I downloaded Fiddler. It told me where the page was going when I clicked on products. It was not
"sfa/opps/edit.aspx?"
but
"/sfa/opps/areas.aspx?".
Also, it should be navProds and areaProds.

Hope this helps,

Michael

Unknown said...

Can I use custom filtering in activities based on a custom attribute (e.g. specific department) when showing the history in CRM 4.0?

Matt Wittemann said...

Not using this technique, but you could put an custom .aspx page in your iframe that shows what you need.

Anonymous said...

Hello,

Just wanted to thank you for this. It was well written. I now understand it well enough that I may start experimenting. Hopefully, nothing will blow up! :)

Thanks again for your time

wasekhpatel said...

Anyone knows how to put more than two Iframes on a form.Let's consider one scenario i want to display associated contacts, leads and opportunity on Account form.

Anonymous said...

Hi Matt

Do you know how to remove the grid tool bar in an IFRAME &????

Pete

Anonymous said...

Hope someone can help me with this: I have an iframe in leads show history for completed activities. When a lead is opened, the lead will show the history but i can not click on an of the associated activites to load them. I have my crm web page set as a trusted website. Also, when i hit F5 (this refreshes the webpage) i can then click on the activities in the IFrame. Odd.

Anonymous said...

Excellent stuff and it works great with a custom entity that has a "1 to many" relationship it, when I change the relationship to "many to many" it does not work. I looked at the source of the page and now I see the loadarea now has an "area" prefixed but I get an invalid argument, when I use that new value. I'm missing something basic, but don't know enough about this.

Any help is appreciated, has anyone figured this out?

Anonymous said...

Excellent stuff and it works great with a custom entity that has a "1 to many" relationship it, when I change the relationship to "many to many" it does not work. I looked at the source of the page and now I see the loadarea now has an "area" prefixed but I get an invalid argument, when I use that new value. I'm missing something basic, but don't know enough about this.

Anonymous said...

Thanks for this info it works great with 1 to many relationships. Like others here, I am trying to do the same with a many to many relationship, but keep getting invalid argument. Does anybody know how to make this work with crm 4 many to many relationships? I have looked through the source of the main page and located the loadarea parameter (areanew_contact_new_sale) and given it the correct object type and security codes - it seems so close but no cigar. (invalid argument)

Anonymous said...

I've successfully added the Relationships area to the Account entity in an IFrame but receive this message when I try to create a new Customer Relationship in the IFrame:
Error - Record is Unavailable >> The requested record is unavailable or you do not have sufficient permissions to view it.

I am a System Administrator..
Any thoughts?
~Maria

Yuri said...

Hi everybody
Thanks Matt
Nice post, but I have some problems with it.
My task is to show opportunities liek you did with History

i didn't add iframe via =>customization.
i create an element('iframe')

the script :
switch (crmForm.FormType)
{
case CRM_FORM_TYPE_UPDATE:
case CRM_FORM_TYPE_READONLY:
case CRM_FORM_TYPE_DISABLED:
var createdElement = document.createElement("iframe");
createdElement.id = "oppsFrame";
createdElement.style.backgroundcolor = "#ffffff";
createdElement.style.width = parentElement.offsetWidth;
createdElement.style.height = "500";
createdElement.removeNode(true);

createdElement.src="/sfa/conts/areas.aspx?oId=" + crmForm.ObjectId + "&oType=" + crmForm.ObjectTypeCode + "&security=" + crmFormSubmit.crmFormSubmitSecurity.value + "&tabSet=areaOpps";
parentElement.appendChild(createdElement);


break;
}

I get the window for opportunities where i want to get it,but it is empty-no records (if i choose opportunities from nav menue- i get 2 records )

The second problem is when i tried to make "New Opportunity" -i've got CRM Exception :
[CrmObjectNotFoundException: contact With Id = 51639e7d-be92-dd11-a862-0003ffd47388 Does Not Exist]
at Microsoft.Crm.BusinessEntities.BusinessProcessObject.Retrieve(BusinessEntityMoniker moniker, EntityExpression entityExpression, ExecutionContext context, Int32[] deletionCodes, Int32 languageCode)
at Microsoft.Crm.BusinessEntities.BusinessProcessObject.Retrieve(BusinessEntityMoniker moniker, EntityExpression entityExpression, ExecutionContext context, Int32[] deletionCodes)
at Microsoft.Crm.BusinessEntities.BusinessProcessObject.Retrieve(BusinessEntityMoniker moniker, EntityExpression entityExpression, ExecutionContext context)
at Microsoft.Crm.ObjectModel.CustomizationService.InitializeFrom(BusinessEntityMoniker moniker, String

What is wrong?!

Yuri

Anonymous said...

This is awesome! I've applied this to Activities Associated with Contacts, Accounts, & Contracts so far. It works great except for Contracts. I thought I had updated the url & the object type correctly. Any help with the CONTRACTS would be greatly appreciated...

CONTACTS
var navActivityHistory;
navActivityHistory =
document.all.navActivityHistory;

if (navActivityHistory != null)
{
navActivityHistory.style.display = "none";
document.all.IFRAME_HistoryFrame.src="/sfa/conts/areas.aspx?oId=" +
crmForm.ObjectId +
"&oType=2&security=852023&tabSet=areaActivityHistory";
}
else
{
alert("navHistory Not Found");
}

ACCOUNTS
var navActivityHistory;
navActivityHistory =
document.all.navActivityHistory;

if (navActivityHistory != null)
{
document.all.IFRAME_HistoryFrame.src="/sfa/accts/areas.aspx?oId=" +
crmForm.ObjectId +
"&oType=2&security=852023&tabSet=areaActivityHistory";
}
else
{
alert("navHistory Not Found");
}

CONTRACTS


var navActivityHistory;
navActivityHistory =
document.all.navActivityHistory;

if (navActivityHistory != null)
{
navActivityHistory.style.display = "none";
document.all.IFRAME_HistoryFrame.src="/cs/contracts/areas.aspx?oId=" +
crmForm.ObjectId +
"&oType=1010&security=852023&tabSet=areaActivityHistory";
}
else
{
alert("navHistory Not Found");
}

Anonymous said...

UPDATE to the previous POST:

That code works for all 3 entities, including Contracts. One of my Field's OnChange Events was causing the problem with Contracts.

 
ICU MSCRM © 2004-2009