Adding Attach File button on Custom Activity Type Entity

MS CRM 2011 introduced a new feature to create custom activity type entity. While creating custom activity type entity, even if we will enable Notes (include attachments), we won’t get Attach File button just like we used to get in any custom entity where Notes is enabled. So what if you want to get that button?? you just need to follow this post 🙂

To create custom Attach File button we need

  1. A Webresource to form notes URL.
  2. We need Attach File image to show it in custom Ribbon button.
  3. We need to create custom Ribbon Button.

 Let’s first create webresource to open notes dialog.

Let’s first create a solution and add our custom activity to that solution. Once entity is added create a new web resource let’s say Notes.js and add below function to that webresourc

function FileAttachment()


var EntityID; // to get entity id

var ServicerURL=Xrm.Page.context.getServerUrl(); // to get server url

var NotesURL=ServicerURL+”/notes/edit.aspx?hideDesc=1&pId=”+ EntityID +”&pType=”;

var etc = Xrm.Page.context.getQueryStringParameters().etc; // to get entity type code, make sure not to hard code it, because it could changed in another deployment

var features = ‘copyhistory=no,top=110,left=280,width=600,height=30’;

openStdWin(NotesURL +etc,””,features);


Save and close webresourc and publish it.

Let’s create a .png  image webresource to store image for attachment ribbon button. Follow below steps to create image webresource

  1. Navigate to Solution->Webresourc and click New
  2. Enter below information
  • Name: AddAttachment_16.png
  • Display Name: AddAttachment_16
  • Type: PNG format
  • Language: English

** we need to upload attachment_16.png, You can find this image for attachment in sdkresourcesimagesribbon folder.

we need to follow same steps to create webresourc for attachment_32.png image.

Now we have our web resources ready so let’s create our custom ribbon button. Export solution as unmanaged state and unzip solution. We need to edit customization.xml file in visual studio and add below code for Ribbon definition:



          <CustomAction Id=”MYDEMO.Form.new_CustomActivity.MainTab.Actions.attachment.CustomAction” Location=”Mscrm.Form.new_CustomActivity.MainTab.Actions.Controls._children” Sequence=”41″>


              <Button Id=”MyDemo.Form.new_CustomActivity.MainTab.Actions.attachment” Command=”MYDEMO.Form.new_CustomActivity.MainTab.Actions.attachment.Command” Sequence=”29″ ToolTipTitle=”$LocLabels:MYDEMO.Form.new_CustomActivity.MainTab.Actions.attachment.LabelText” LabelText=”$LocLabels:MYDEMO.Form.new_CustomActivity.MainTab.Actions.attachment.LabelText” ToolTipDescription=”$LocLabels:MYDEMO.Form.new_CustomActivity.MainTab.Actions.attachment.Description” TemplateAlias=”o1″ Image16by16=”$webresource:MyDemo_Attachment_16.png” Image32by32=”$webresource:MyDemo_Attachment_32.png” />





          <RibbonTemplates Id=”Mscrm.Templates”></RibbonTemplates>



          <CommandDefinition Id=”MYDEMO.Form.new_CustomActivity.MainTab.Actions.attachment.Command”>


              <EnableRule Id=”MYDEMO.Form.new_CustomActivity.MainTab.Actions.attachment.Command.EnableRule.FormStateRule” />


            <DisplayRules />


              <JavaScriptFunction FunctionName=”FileAttachment” Library=”$webresource:MyDemo_Attachment.js” />





          <TabDisplayRules />

          <DisplayRules />


            <EnableRule Id=”MYDEMO.Form.new_CustomActivity.MainTab.Actions.attachment.Command.EnableRule.FormStateRule”>

              <FormStateRule State=”Existing” Default=”false” InvertResult=”false” />





          <LocLabel Id=”MYDEMO.Form.new_CustomActivity.MainTab.Actions.attachment.Description”>


              <Title languagecode=”1033″ description=”attachment Description” />



          <LocLabel Id=”MYDEMO.Form.new_CustomActivity.MainTab.Actions.attachment.LabelText”>


              <Title languagecode=”1033″ description=”Attach File” />





Zip your solution and import it. Now you should be able to see attachment button in your custom entity under action group like below


make sure to rate this post if you like it 🙂

11 thoughts on “Adding Attach File button on Custom Activity Type Entity

  1. ICK

    Hi! Thanks for the article. I have the same issue and tried to follow these steps. But I have a problem. I can’t import the solution. When I try it, I receive an error message saying that the xml file is not valid. It’s really extrange, because, when I export the solution and unzip the file, I have no problem to see the customization.xml file. But after edit it (I try whit Visual Studio, Notepad, Notepad ++), I can’t read it anylonger using internet explorer. I don’t know why!
    Here are my questions:
    1. When I have to import the solution, which components I have to include? I guess, the entity and the 3 webresources (2 for images and the first one).
    2. When I edit the RibbonDiffXml section, I have to delete the actual information.

    I hope you can help me and sorry for the english.

    1. mahenderpal Post author

      1. When I have to import the solution, which components I have to include? I guess, the entity and the 3 webresources (2 for images and the first one)- yes.
      2. When I edit the RibbonDiffXml section, I have to delete the actual information- It depends if you have not customized ribbondiffxml already then you can replace complete with this code, but if you have already customized it then you need to append this code in existing ribbondiffxml.

      let me know if you need any other information.

  2. ICK

    Thanks for your reply Manhender Pal. I found the problem with customization.xml file. It was just a typing mistake, I had to rewrite the symbol ” ” again. Now, I have another error and the importation failed. The message is “The ribbon item ‘MYDEMO.Form.new_CustomActivity.MainTab.Actions.attachment.CustomAction’ is dependent on ribbon control id=’Mscrm.Form.new_CustomActivity.MainTab.Actions.Controls’.”. I think missed a step. When you say: “Now we have our web resources ready so let’s create our custom ribbon button. ” Is there something else to do before customize the xml file?

    Sorry for bother you again!!! regards!!

    1. mahenderpal Post author

      ’Mscrm.Form.new_CustomActivity.MainTab.Actions.Controls’ this is the id of the main tab where I am creating this button, you need you are specifying correct parent group id here, where you want to place this button. you can generate riboon xml for all entity using ribbon utility available in SDK under “C:MSCRM_2011sdksamplecodecsclientribbon” locatoin and then you can find out group id where you want to place this button. let me know if you need any other information.

  3. Mugdha

    Hi ,
    I tried this and it’s really effective solution that i found.
    But the thing is when I am creating new record that time I will not get EntityID.Getting Null In that case it fails..Please suggest any solution for that.

  4. Karthik

    This seems to be a neat solution. However, I’m facing some problems to get it working. Im not an expert in coding, but I would really like to have this feature in the system. Now here is where I am:

    1. Created 3 web resources
    2. Exported the solution Default_1_0
    3. Edited the customization.xml file – Ctrl-F against ribbon, replaced all the coded under this entity to the one suggested here.
    4. Replaced all MYDEMO with the name of custom activity I created.
    5. Did not remove any existing web resource under “web resource” folder.
    5. Saved and tried to import the zip file under solutions.

    At this point while importing, I get an error saying : ” The solution is invalid. The compressed file must contain the following files at its root: solution.xml, customization.xml, and [Content_Types].xml. Customization files exported from previous versions of MCRM are not supported”

    Am I doing something blatantly wrong here? Any help is much appreciated.

    1. mahenderpal Post author

      Hi Karthik, I suspect that you are not compressing your solution correctly, In Windows Explorer, you need select all the files. Then right-click and select Send To and Compressed (zipped) folder and then rename it with your solution name that you exported and then import.


Leave a Reply

Your email address will not be published. Required fields are marked *