{Knowhow} Get count of Attachments for Email in Dynamics CRM without code

Recently we had a requirement from our customer to show the number of attachments for each email in a view. The number needs to be reflected whenever the user refreshes the view.

Simple requirement right? And what is coming to your mind? Plugins? Workflows?

Well if you are thinking of the Plugins and workflows, I am sure you are not alone. In fact the first thing that came to my mind was the same. But we are in CRM 2016 right? And is there no other way to achieve this?

I brainstormed for sometime and then came up with the below solution. Believe me it is a simple solution without any code and I am pretty sure you would like it. No it is not rollup field. It is using the calculated field feature of Dynamics CRM.

Let us first look at the email entity in CRM. A quick glance at the email entity and you could see there is field already in the email entity called ‘Attachment Count’. Wow! Can’t we use this field. Unfortunately the answer is ‘No’. If you open this field, it is a non-editable field and it won’t appear in your view and advanced find as well. Nor you can use it in roll-up fields or calculated fields editor. Sad isn’t it.

 

image

image

I was pretty sure that this field could give us the count of attachments for an email. But how to get around the limitation. Well you have CRM 2016 after all which is just awesome. All we consultants need to do is to explore it a bit to make it work for all situations Smile

To start with I created a solution with the email entity in it. And then I created a dummy field called ‘Attachment Count Dummy’. Don’t worry I am just creating a dummy field here. I will delete it later when done. As of now just make sure you make the field as ‘whole number’ type.

image

 

Great. So we are done with our first step. Now we create our real field to store the attachments. I name it the same ‘Attachment Count’ of type whole number. But this I make it a calculated field.

image

I set it to be equal to ‘Attachment count dummy’ field. You may be asking why not set this field to the OOB attachmentcount field. Because as I mentioned before, the OOB attachmentcount field cannot be used in calculated field editor.

image

Save and close the editor. Include this calculated field in whichever views you want.

All set and done. Now comes the real trick. Publish everything and export the solution. Once the solution is exported, unzip it and you would see the contents. It should have a Formulas folder where CRM stores all the calculated field formulas.

image

 

Open the folder and then open the formula of the ‘Attachment Count’ calculated field .xaml file in a xml editor of your choice. Replace the dummy field name with the name ‘attachmentcount’.  Note this is the most important step.

 

Before:

image

 

After:

image

Save and close the file. Now zip the contents of the solution back and import the solution again in your CRM environment. Once the publish is completed, open advanced find and then check for the views

image

I open my email, attach one more attachment and as soon as I refresh the view, I could see the count being incremented.

image

 

Are we missing something here? Yes. You remember we created an extra dummy field. Go ahead and delete it. It won’t do any harm if you delete it. But you would be left with an unnecessary field.

Wonderful isn’t it? I hope you liked the idea.

Advertisements

Author: 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

2 thoughts on “{Knowhow} Get count of Attachments for Email in Dynamics CRM without code”

  1. great solution and with simple approach… but i m not sure if it is supported way fixing the problem? please correct if I am wrong

    1. Strictly speaking, opening the customizations and making changes is documented as unsupported by Microsoft. From that angle, yeah it’s unsupported. But again having worked in multiple client engagements I had to do that many a times for multiple scenarios :). Coming to this example, what I found is there are many stuffs which the framework is able to take care of but the UI does not support that. So no other option but to manually update the customizations file.

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