Enabling Mail Merge Template for other System entities

Hi,

We had a requirement to use the exiting templates for salesorder entity. However as we know, we only get the option of Lead, Opportunity, Contact , Account , Quote and other custom entities in Associated Entity drop down for the mail merge template.

So i first tried out this, exported the customization for the salesorder entity and added attribute IsMailMergeEnabled with the value of 1, imported it and published it.

However this didn’t work, it only works for custom entities.

Than i tried to do the same using the Metadata Service.

// Initialize MetadataService
MetadataService mdService = new MetadataService();
mdService.Credentials = System.Net.CredentialCache.DefaultCredentials;
mdService.CrmAuthenticationTokenValue = new CrmAuthenticationToken();
mdService.CrmAuthenticationTokenValue.AuthenticationType = 0;
mdService.CrmAuthenticationTokenValue.OrganizationName = "orgname";

// Use RetrieveEntityRequest to get the metadataid for the sales order entity
RetrieveEntityRequest entityMDRequest = new RetrieveEntityRequest();
entityMDRequest.LogicalName = "salesorder";
entityMDRequest.EntityItems = EntityItems.EntityOnly;
RetrieveEntityResponse entityMDResponse1 = (RetrieveEntityResponse)mdService.Execute(entityMDRequest);

// Initialize EntityMetadata for the salesorder entity
EntityMetadata entityMD = new EntityMetadata();
entityMD.MetadataId = entityMDResponse1.EntityMetadata.MetadataId;
// Set IsMailMergeEnabled to true
entityMD.IsMailMergeEnabled = new CrmBoolean();
entityMD.IsMailMergeEnabled.Value = true;

// Use UpdateEntityRequest to update the metadata for sales order entity
UpdateEntityRequest ueRequest = new UpdateEntityRequest();
ueRequest.Entity = entityMD;
UpdateEntityResponse ueResponse = (UpdateEntityResponse)mdService.Execute(ueRequest);

However it gave the following error

"<error>\n  <code>0x80040203</code>\n  <description>Entity 38ded7b5-9ec6-4e77-919a-c408023a4db4 is not a custom entity and therefore cannot have its mail merge enabled properties changed</description>\n  <type>Platform</type>\n</error>"

Finally then i tried out this,

Updated the value for IsMailMergeEnabled in the organization database itself.

This is the sql query for that

update MetadataSchema.Entity
set ismailmergeenabled=1
where name=’salesorder’

Followed by an IISReset.

And it worked !!!!  ( however it is unsupported !!! )

I was able to see the order entity in the Associated Entity drop down for the mail merge template.

I am yet to test it thoroughly though !

Check out this post as well

https://nishantrana.wordpress.com/2009/10/07/using-mail-merge-for-other-entities-in-crm-4/

Bye..


Author: Nishant Rana

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

6 thoughts on “Enabling Mail Merge Template for other System entities”

  1. Hi.
    Has anyone ever succeeded with making the MailMerge button/function work on the FORM? I can make it work on the GRID, but not the form. Need help…

    Like

  2. I run the script, reset IIS but I can´t see Order entity in the templates list. This solution also is valid using rollup 10?

    Like

  3. I have done this and it worked great, but everytime i come back it is missing from the list even though the value is still set to 1 in the database.

    Like

  4. Nishant,
    Thank you so much for this unsupported customisation trick. I have been searching the net for a long time for this, and the database hack followed by iisreset saved us from a lot of hassles.

    Thank you for posting this.

    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