Update owner in Plugin

Here's a code snippet that will help you to update the owner of a record in a plug-in. This code should run in a POST plug-in:


SecurityPrincipal assignee = new SecurityPrincipal();
assignee.Type = SecurityPrincipalType.User;

// PrincipalId is some known Guid belonging to the user or team that will own this record.
assignee.PrincipalId = new Guid("476E234C-5E15-DE11-80BA-000C297AF856");

// Create the target object for the request.
TargetOwnedAccount target = new TargetOwnedAccount();

// Set the properties of the target object.
// EntityId is some known Guid belonging to the account that is being assigned to the user.
target.EntityId = id;

// Create the request object.
AssignRequest assign = new AssignRequest();

// Set the properties of the request object.
assign.Assignee = assignee;
assign.Target = target;

// Execute the request.
ICrmService service = context.CreateCrmService(true);
try
{
AssignResponse assignResponse = (AssignResponse)service.Execute(assign);
}
catch (Exception ex)
{
//TODO: Exceptionhandling
}


Have fun copy and pasting :)



Links in e-mail templates

It is not so hard to get a link in a CRM template, but to hide the link behind your custom text is more difficult. It is possible to do so though. I noticed a small post in the communities by my fellow MVP Adi Katz in which he explains how you can do this. This post does deserve a bit more attention so that's why I am copying the content in this blog post. And now I can find it back as well :)

Adi Katz:
You need to create a new text attribute (e.g. new_workflowhref ) that holds an entire Anchor HTML tag with the HREF property set to the desired link.

Here is a simple example:


<a href=”http://[server]:[port]/[organization name]/userdefined/edit.aspx?etc=10016&id=40f03814-8544-dd11-b4d5-0003ff230264”>click here for more information</a>

You need to set this attribute on a post create event using a plug-in OR you might use Ajax to set this attribute when the form returns after creation e.g.

crmForm.FormType == 2 && crmForm.all.new_workflowhref.DataValue == null

Insert the new_workflowhref field inside the email body. The workflow should run when the new_workflowhref changes.

Cheers,
Adi



Document your CRM installation

Everybody knows the importance of documentation of a project. Thanks to Merijn van Mourik and some other guys there is a tool which can help you documenting your solution. This is a free tool which you can download from Codeplex: CRM 4 documentation.

If you want to use this tool on a standalone machine or a machine without internet connection, then you should download and install the following files first:

vstor30.exe
vstor30sp1-KB949258-x86.exe

I do know that this is not a new tool, but not everybody heard about this before. Happy documentation!



Action Microsoft.Crm.Config.Client.InstallPstAction failed

While installing the Outlook Client, there is one error that appears to be popping up more than others:


Action Microsoft.Crm.Config.Client.InstallPstAction failed.
LaunchOutlookInstallerProcess failed.

There are some blog posts which offer solutions to this error message. If you have this message, try the following:
- Run %windir%\system32\fixmapi.exe
- Reinstall the client
- Install latest rollup of the Dynamics CRM for Outlook client (same version as on server)

Or look at the following blogs:
- http://blogs.msdn.com/crm/archive/2009/05/29/troubleshooting-the-microsoft-dynamics-crm-client-for-outlook.aspx
- http://blogs.msdn.com/mscrmfreak/archive/2006/06/12/627955.aspx

Now these solutions didn't fix the error for one of our clients. Thanks to my colleague Wouter de Nooij we solved this by setting the Microsoft Office language to English. Then redo the configuration (using Start > Microsoft Office > Microsoft Office Tools > Microsoft Office 2007 Language Settings). After that the configuration succeeded. Resetting the language setting to Dutch did not result into problems, so all is well now.

Update:
One more solution to add to the list:
- Provide write access to the file C:\Program Files\Common Files\System\MSMAPI\1033\MAPISVC.INF or "Program Files (x86)" for 64bit machines.

Please let me know if you find other solutions for this error message!



Remove attributes from form which cannot be removed

There are some attributes on CRM default forms which you cannot remove. This post will show you how you can do this anyway. While doing so, please keep in mind that Microsoft must have good reasons to fix attributes on the form. Removing this might have implications, as always have a good backup ready.

The steps you need to follow to remove are:
- Export customizations for the specific entity
- Modify the form in the customizations xml
- Import the modified customizations

Since most of you are well known with CRM I will skip the Export and Import of customizations. If you need assistance with this, then don't try this change anyway :) To modify the customizations, open the file in notepad or another XML editor. In this file look for this path:

ImportExportXml - Entities - Entity - FormXml - forms - entity - form - tabs

Within tabs look for the tab with the correct name and similar for the sections. Get a bit familiar with the section xml once you have found the correct section. You'll find that there are a couple of lines that you need to remove. This is the example for the subjectid on the case entity:


<cell id="{a9859c32-0cdc-41b5-8e7e-3eb173cab4a8}">
<labels>
<label description="Onderwerp" languagecode="1043" />
<label description="Subject" languagecode="1033" />
</labels>
<control id="subjectid" classid="{270BD3DB-D9AF-4782-9025-509E298DEC0A}" datafieldname="subjectid" />
</cell>


Attributes which are locked on the form includes the following:
case - subjectid
case - contractid
case - contractdetailid

Note: Some of the attributes are used in hidden javascript codes. For instance the case contract contractid is used in the script for the customer onchange. You can also look at removing those scripts from the customizations file.



Changing default organisation

You can change the default organisation by opening the configuration manager. In this tool you can rightclick on the organisation which you want to set as default and click "set as default". You'll see that the name of the organisation has changed to: Orgname (default).

After you perform an IISReset you would expect the new default organisation to open up when you browse to your CRM server. Unfortunately that doesn't work immediately. My fellow MVP Marco Amoedo wrote this post in the community to explain why and how to change that behavior:

Hi Tony,

The default organisation will no change for the already created users, this change will only be applied for new users created after the change. This means that this changes is not applied in a retroactive fashion, only the new users that you create will have that organisation as default.

Each user record have stored the default organisation, so you would need to change them for each one of the already created users. You have two mechanisms. Either use this tool provided by Microsoft Support

Or directly modify the CRM Database to change the DefaultOrganizationId on the SystemUser table (like it is proposed here http://chicagotech.net/netforums/viewtopic.php?t=6046)

In either case, make a backup of the databases before just in case.

Hope it helps

Marco Amoedo



Change the CRMAppPool Identity

Most likely this is recorded in a thousand places, but I had a hard time finding info about what steps need to be taken to change the identity of the CrmAppPool. All you need to do is:
- Create a user in Active Directory
- Make sure the user has Domain User rights
- Add the user to the PrivUserGroup of CRM
- Make sure the user has 'log on as a service' priviledge

The last step can be executed on two approaches:
- Go to 'Local Security Policy' in the administrative tools ('Domain Controller Secuirty Settings' on a Domain Controller) and add the user to 'Log on as a service'
- Add the user to the CRM_WPG group in AD. This group is member of the 'Log on as a service' policy.

Hope this saves you some time, at least now that I have this documented here I can find it back *smile*