Saturday, July 26, 2008

Changing the Activity / History default view

The associated activity and history views within a given entity are not customizable and you cannot change their default view settings.
Although this type of DOM manipulation is unsupported, if this is a “must have” requirement you can implement the change with the following js script.

put the code inside the entity onload event.


//Activity scheduledend options
var ActivityOptions =
{
All : "All",
Overdue :"Overdue",
Today :"Today",
Tomorrow :"Tomorrow",
Next7Days :"NextXDays;7",
Next30Days :"NextXDays;30",
Next90Days :"NextXDays;90",
Next6Months :"NextXMonths;6"
}

//Activity History actualend options
var HistoryOptions =
{
All : "All",
Today : "Today",
Yesterday : "Yesterday",
Last7Days : "LastXDays;7",
Last30Days : "LastXDays;30",
Last90Days : "LastXDays;90",
Last6Months : "LastXMonths;6",
Last12Months: "LastXMonths;12"
}

var _loadarea = loadArea;
loadArea = function(sArea, sParams, sUrl, bIsvMode)
{
//load the iframe
_loadarea(sArea, sParams, sUrl, bIsvMode);

if( sArea != "areaActivityHistory" &&
sArea != "areaActivities" ) return;

//create the iframe object
var iframe = document.getElementById(sArea + "Frame");
//wait until the iframe is fully loaded ("complete")
iframe.onreadystatechange = function()
{
if( iframe.readyState == "complete")
{
var picklist,option;
//reference to the iframe document
var iframeDoc = iframe.contentWindow.document;
switch(sArea)
{
case "areaActivityHistory":
picklist = iframeDoc.all.actualend[0];
/* change to suit your needs */
option = HistoryOptions.Last90Days;
break;
case "areaActivities":
picklist = iframeDoc.all.scheduledend[0];
/* change to suit your needs */
option = ActivityOptions.Next7Days;
break;
default: return;
}
picklist.value = option;
picklist.FireOnChange();
}
}
}

33 comments:

Bigcalm said...

Gold Star!

Thankyou so much, worked like a charm!

You're missing
All: "All";

in History options though.

Anonymous said...

It works almost perfectly,BUT it creates an "error on page" when you navigate back to the Information view.

Adi Katz said...

Hi,

Added lines 33,34 to fix this issue.

Adi

Anonymous said...

Hi Adi,

Great Script.

I'm having a little problem because of some other customizations:

I've added a functionality so that you could choose what type of account you are storing. When you choose from this dropdown list, the left navigation list change from the standard activity-list view, to a custom-made asp. file that shows all activities in parent structure. It's still the same link: areaActivity, but it's no longer the areaActivitiesFrame. It's parentEntityActivitiesFrame.

When I use this code, it works fine. Until the code tries to set this view to Last 90 days. I think it's something about the iframe having a different ID. Or that the asp file does not include "filter on". Do you know some kind of if sentence i could use to prevent this error to occur?

Adi Katz said...

Hi,

You need to add the asp iframe areaid to line 33 conditions and make sure the iframe id is areaid + "Frame".

If indeed your custom iframe shows the original activities associated view i don't see why this shouldn't work.

Adi

Anonymous said...

Thanks for your reply. I’ve tried that, and that does not seem to be the problem.

Instead of showing standard activity view, the asp files i’ve implemented is customized. It has no “filter on” dropdown and it views activities for more than one company.

This works without the code. But with the code, I keep getting a white error page. The link on the navigation pane is still activities though.

Using the ID Developer Toolbal, I found these values for the the Iframes and Areaid(?!)
The logic is:

When the company record is set to customer the standard activity view is shown, and the values are:
Div Id: areaActivities
IFRAME id: areaActivitiesFrame

When the company record is set to Parent Entity the customized asp file is shown with the asp file saved in userdefined with another advanced find view.
Div id = parentEntityActivitiesArea
IFRAME id = parentEntityActivitiesAreaFrame

What i’m trying to do is deactivate the code for the customized asp file. It’s not necessary there, so this would solve the problem. Do you know what to do?

Adi Katz said...

Hi Jorn,

Line 33 has a condition that checks for “areaActivityHistory” or “areaActivity” area ids which means that other iframe except for activity iframes(ids) are not intercepted.

I don’t understand why the code is not working for you as is.

Anonymous said...

Ok. I don't really understand it either. Because as long as you customize the navbar from the ISV config, it seems like the script will make a conflict. No matter what content you have in the iframe.

Anyways, thanks for your help. If you get any idea on how it could be solved. Please post it.

Regards,
Jorn

Anonymous said...

Adi,

Thanks for your code. This looks like it should do what I need. I am trying to get it to work with the Cases Associated View. The following is the code I am using, but it does not do anything.

//Case History statecode options
var ServiceOptions =
{
Active : "0",
Resolved : "1",
Canceled : "2",
All : "All"
}

var _loadarea = loadArea;
loadArea = function(areaid)
{
//load the iframe
_loadarea(areaid);

if( areaid != "areaService") return;

//create the iframe object
var iframe = document.getElementById(areaid + "Frame");
//wait until the iframe is fully loaded ("complete")
iframe.onreadystatechange = function()
{
if( iframe.readyState == "complete")
{
var picklist,option;
//reference to the iframe document
var iframeDoc = iframe.contentWindow.document;
switch(areaid)
{
case "areaService":
picklist = iframeDoc.all.statecode[0];
option = ServiceOptions.All;
break;
default: return;
}
picklist.value = option;
picklist.FireOnChange();
}
}
}

Any ideas? Thanks!

Adi Katz said...

Hi Clark,

I tested the code on the account entity and it works like a charm.

My only conclusion would be that it’s working but not loading into the account form.

I’ll add your code to my blog for better presentation.

thanks,
Adi

Anonymous said...

Hi,

I've been using Dave Hawes code ( http://blog.davehawes.com/post/2008/04/23/MSCRM-4-Remove-Add-Existing-xxxxx-button.aspx ) to remove buttons in associated view. But when i use your filter code and Daves remove button code at the same time there's a conflict. Do you know a way to combine these two codes?

Anonymous said...

The Script above will not work with custom buttons. There are 4 parameters that the loadArea function is expecting. Here is the code updated.


//Activity scheduledend options
var ActivityOptions =
{
All: "All",
Overdue: "Overdue",
Today: "Today",
Tomorrow: "Tomorrow",
Next7Days: "NextXDays;7",
Next30Days: "NextXDays;30",
Next90Days: "NextXDays;90",
Next6Months: "NextXMonths;6"
}

//Activity History actualend options
var HistoryOptions =
{
All: "All",
Today: "Today",
Yesterday: "Yesterday",
Last7Days: "LastXDays;7",
Last30Days: "LastXDays;30",
Last90Days: "LastXDays;90",
Last6Months: "LastXMonths;6",
Last12Months: "LastXMonths;12"
}

var _loadArea = loadArea;
loadArea = function(sArea, sParams, sUrl, bIsvMode) {
//load the iframe
_loadArea(sArea, sParams, sUrl, bIsvMode);

if (sArea != "areaActivityHistory" && sArea != "areaActivities") {
return;
}

//create the iframe object
var iframe = document.getElementById(sArea + "Frame");
//wait until the iframe is fully loaded ("complete")
iframe.onreadystatechange = function() {
if (iframe.readyState == "complete") {
var picklist, option;
//reference to the iframe document
var iframeDoc = iframe.contentWindow.document;
switch (sArea) {
case "areaActivityHistory":
picklist = iframeDoc.all.actualend[0];
/* change to suit your needs */
option = HistoryOptions.All;
break;
case "areaActivities":
picklist = iframeDoc.all.scheduledend[0];
/* change to suit your needs */
option = ActivityOptions.All;
break;
default: return;
}
picklist.value = option;
picklist.FireOnChange();
}
}
}

Adi Katz said...

I have not tested it with isv buttons, thanks for the fix.

Andy said...

Adi,

I have a silly question, but I'm having trouble finding the proper entity to apply the code inside the entity onload event. Would you please direct me to where the History form resides? All I can find are views for this section. Your help is greatly appreciated.

Thanks,
Andy

Anonymous said...

Hi Adi,

Just a quick question...Using your code would I be able to add two new columns in history view to show (from) and (to) as this will be very helpful when i am going over the history..

Adi Katz said...

Andy, any entity that has activities can utilize this code.

Anonymous, the code only helps you change the default history / activities view and does not add columns to the view.

Anonymous said...

Hi Adi,

Thanx for your response. What I meant was that can I add the "to" and "from" fields found in the email activity in the history view which is not there currently.....

Thanx

Adi Katz said...

This is impossible to do with JavaScript. You might try hooking to the RetrieveMultiple message and bring the “from” an “to” columns into existing activity attributes like category and subcategory.

Since the view presents all types of activities showing attributes from a specific activity like email is not a simple task.

DigiOz Multimedia said...

Very useful code. Thanks for sharing it with us.

Pete

Anonymous said...

Where to I place the code? I went ot the Customize Entities> Account>Form and Views... I am unsure of the next step.

Adi Katz said...

Form and Views --> Form --> Form Properties --> select onload --> edit --> paste the code, save and publish.

Anonymous said...

It worked perfect. Thanks you!

Swan said...

it always prompt me loadArea is undefined since i added a custom button through iFrame in the Contact's Entity.

With the updated code, it still not work.

i should do something in my custom button?

Unknown said...

Hi,
I have a requirement to change the order of the activity lookup when you click on activities. The order has 'Task'at the top. I want to change it to have Email at the top. Can anyone help please.

Monica said...

Hi Adi,

Do you know if we can do this on the main Activities view from Workplace(not associated view)?

Adi Katz said...

Consider Creating a new sitemap link to a custom aspx with an iframe pointing to Workplace/home_activities.aspx, wait until the home_activities loads and change the picklist values using script.

Mac said...

Adi, thank you for your contribution. I've read the whole blog/comments but I'm not sure how to add new options to "Filter On" picklist. I'd like a new value to say "Leads" and when the user picks that, it would fill the bottom grid with tasks where the "subject" field "starts with" the string: "New Lead: ". Is that possible? and also have this custom value only visible on the Contacts History, not all History associated entities.

Anonymous said...

I put the code in the onLoad event of the form, but in form properties, in form events we add the javascript file to a library and onload event we add the name of library and function name, there is no function name in this case ...do we wrap the javascript in this inside a function such as Function Activity ???
Concerning loadArea = function(sArea, sParams, sUrl, bIsvMode)
from where the parameters are passed ????


thanks
Function Activity
{

//Activity scheduledend options var ActivityOptions = { All : "All", Overdue :"Overdue", Today :"Today", Tomorrow :"Tomorrow", Next7Days :"NextXDays;7", Next30Days :"NextXDays;30", Next90Days :"NextXDays;90", Next6Months :"NextXMonths;6" } //Activity History actualend options var HistoryOptions = { All : "All", Today : "Today", Yesterday : "Yesterday", Last7Days : "LastXDays;7", Last30Days : "LastXDays;30", Last90Days : "LastXDays;90", Last6Months : "LastXMonths;6", Last12Months: "LastXMonths;12" } var _loadarea = loadArea; loadArea = function(sArea, sParams, sUrl, bIsvMode) { //load the iframe _loadarea(sArea, sParams, sUrl, bIsvMode); if( sArea != "areaActivityHistory" && sArea != "areaActivities" ) return; //create the iframe object var iframe = document.getElementById(sArea + "Frame"); //wait until the iframe is fully loaded ("complete") iframe.onreadystatechange = function() { if( iframe.readyState == "complete") { var picklist,option; //reference to the iframe document var iframeDoc = iframe.contentWindow.document; switch(sArea) { case "areaActivityHistory": picklist = iframeDoc.all.actualend[0]; /* change to suit your needs */ option = HistoryOptions.Last90Days; break; case "areaActivities": picklist = iframeDoc.all.scheduledend[0]; /* change to suit your needs */ option = ActivityOptions.Next7Days; break; default: return; } picklist.value = option; picklist.FireOnChange(); } } }

}

Anonymous said...

Calling the LoadArea function will cause object expected error because it needs parameters, what are the parameters I need to pass when calling the function.

Mr.RabidCHild said...

Just used this code today. Worked perfect! The only modification I made was to remove the comments and set ActivityOptions and HistoryOptions to "All". Thanks for the good code!

Jan Adamec said...

Hi, please could this be used to change the history view to show appointments only? I mean change or add one of the values in picklist to All appointments and change the view?
Thank you very much Jan (jan.adamec@seznam.cz)

Anonymous said...

in crm2011 on the account form ive added an iframe for activities and then ive used this code to try to set the default filter to "all". but it doesnt work. there are no error messages or anything like that - the filter remains on "last 30 days". any help appreciated.

thanks

Anonymous said...

Thank you! We still have CRM 4.0, and this works great!