Friday, October 19, 2007

How to Identify the currently logged in user using the MSCRM service

I needed to build a custom CRM page that would be hosted within the crm 3.0 environment, it need to be accessed via the navigation pane. Given that requirement the page need to find out which user was logged in.

using the the webservice do the following:

WhoAmIRequest whoAmI = new WhoAmIRequest();
WhoAmIResponse Iam = (WhoAmIResponse)service.Execute(whoAmI);
Guid userid = Iam.UserId;


The WhoAmIResponse includes also includes the business unit belonging to the user.

Oshri Cohen

Labels: , , , , , , , ,

Tuesday, October 16, 2007

How to hide CRM 3.0 menu items

A requirement for one of my clients required me to hide the" save and new" from an entity.

This is very simple to do, essentially the CRM developers named these buttons with a static name that can be accessed within any javascript event.

here is the reference to the most common buttons:


Save = "_MBcrmFormSave"
Save and Close = "_MBcrmFormSaveAndClose"
Save and New = "_MBcrmFormSubmitCrmForm59truetruefalse"
Print = "_MBcrmFormPrint"
Save as completed = "_MBSaveAsCompleted"


to hide the button simply call the following function:

document.getElementById('[name of the button]').Style.Display='None' or 'Inline';

Setting the Style.Display to 'None' will hide the button.

Setting the Style.Display to 'Inline'will Show the button.

*** Please make sure that the menu item actually exists, use this statement for the test:

var mnuItem = document.getElementById('[name of the button]');
if( mnuItem != null)

{
//hide or show here
}

***

I would appreciate if anyone knows the ID name for other buttons to post it as a comment, if you do so i will append it to the post and of course credit you for it.


Have a great Day

Oshri Cohen

Labels: , , , , ,

Monday, October 15, 2007

How to Include JS files in CRM 3.0

I encountered a problem while customizing a CRM 3.0 implementation for a client.
The problem was that the project required a lot of JavaScript and if you have been working with CRM 3.0 you already knows how frustrating it is to develop using JS within crm.

In order to remedy that problem, I thought of using a custom .JS file and include it in the forms that I was customizing. Microsoft clearly states modifying the CRM source pages is not supported or recommended and may not survive an upgrade or a patch.

Here is my solution that may help us all in future CRM 3.0 client side development.

1.
Create your .JS file.

2.
Place it either in a new Virtual Directory within the CRM website or as a separate website all together.

3.
Select the entity that you want to customize and enable the OnLoad event.

4.
Put the following code within the event:

var script = document.createElement("script");
script.type = "text/javascript";
script.src= "[the location of your script either relative or absolute]";
socument.getElementsByTagName("head")[0].appendChild(script);



5.
At this point the .JS file has been appended to the page and has been subsequently loaded by the browser.

***Please note that any modifications to the JS file will require you to clear the browsers Temporary files, otherwise it will not load the latest version. ***

*** this has not been tested for CRM within outlook. ***

Have a great day.

Oshri Cohen

Labels: , , , , ,