Show Attachments for an entity in Custom Webresource in Microsoft Dynamics CRM

Recently in our project we had a requirement where we needed the attachments for an entity in a custom webresource so that when the user clicks the attachment it downloads. For that first of all you would need to get the attachmentid by querying the annotations which are of type attachment for the entity. Once you have the attachmentid, you need to prepare the URL in the below format.

CRM 2011

—————————-

Xrm.Page.context.getServerUrl() + “/Activities/Attachment/download.aspx?AttachmentType={AttachmentType}&IsNotesTabAttachment=1&AttachmentId={” + attachmentId + “}”;

 

CRM 2013

————————-

Xrm.Page.context.getClientUrl() + “/Activities/Attachment/download.aspx?AttachmentType={AttachmentType}&IsNotesTabAttachment=1&AttachmentId={” + attachmentId + “}”;

{AttachmentType} – It has to be specified based on the type of the attachment.

However once you click, you might get an error invalid_wrpc_token.

To overcome this you need to add a key to your registry

1. Go to HKEY_LOCAL_MACHINE -> Software -> Microsoft -> MSCRM in CRM App server

2. Create a new D-WORD ‘IgnoreTokenCheck’. Set value to 1.

3. Restart IIS in the CRM app server.

 

Browse to CRM again and you should be able to download the attachment clicking the URL.

 

Hope this helps!

Advertisements

About Debajit
I am a Dynamics CRM Most Valuable Professional (MVP) with 10 years of experience in Microsoft .NET Technologies and 7 years of dedicated experience in Microsoft Dynamics CRM. I have worked with companies like Microsoft, SanDisk, PwC, TMF Group and have extensive experience of implementing complex CRM solutions from both offshore and client side. Currently the face of XrmForYou.com with significant experience in delivering corporate training on Dynamics CRM and have already delivered multiple projects to client through XrmForYou.com Author of multiple tools on codeplex including the 'Role Based Views' and 'CRM-Sharepoint Metadata manager & Attachment Extractor' which are available for commercial use under XrmForYou.com For consulting/ training, drop me a note at info@xrmforyou.com or visit our website www.xrmforyou.com

Leave a Reply

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

%d bloggers like this: