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 J
To create custom Attach File button we need
- A Webresource to form notes URL.
- We need Attach File image to show it in custom Ribbon button.
- 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 =Xrm.Page.data.entity.getId(); // 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
- Navigate to Solution->Webresourc and click New
- 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 sdk\resources\images\ribbon 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:
<RibbonDiffXml>
<CustomActions>
<CustomAction Id=”MYDEMO.Form.new_CustomActivity.MainTab.Actions.attachment.CustomAction” Location=”Mscrm.Form.new_CustomActivity.MainTab.Actions.Controls._children” Sequence=”41″>
<CommandUIDefinition>
<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” />
</CommandUIDefinition>
</CustomAction>
</CustomActions>
<Templates>
<RibbonTemplates Id=”Mscrm.Templates”></RibbonTemplates>
</Templates>
<CommandDefinitions>
<CommandDefinition Id=”MYDEMO.Form.new_CustomActivity.MainTab.Actions.attachment.Command”>
<EnableRules>
<EnableRule Id=”MYDEMO.Form.new_CustomActivity.MainTab.Actions.attachment.Command.EnableRule.FormStateRule” />
</EnableRules>
<DisplayRules />
<Actions>
<JavaScriptFunction FunctionName=”FileAttachment” Library=”$webresource:MyDemo_Attachment.js” />
</Actions>
</CommandDefinition>
</CommandDefinitions>
<RuleDefinitions>
<TabDisplayRules />
<DisplayRules />
<EnableRules>
<EnableRule Id=”MYDEMO.Form.new_CustomActivity.MainTab.Actions.attachment.Command.EnableRule.FormStateRule”>
<FormStateRule State=”Existing” Default=”false” InvertResult=”false” />
</EnableRule>
</EnableRules>
</RuleDefinitions>
<LocLabels>
<LocLabel Id=”MYDEMO.Form.new_CustomActivity.MainTab.Actions.attachment.Description”>
<Titles>
<Title languagecode=”1033″ description=”attachment Description” />
</Titles>
</LocLabel>
<LocLabel Id=”MYDEMO.Form.new_CustomActivity.MainTab.Actions.attachment.LabelText”>
<Titles>
<Title languagecode=”1033″ description=”Attach File” />
</Titles>
</LocLabel>
</LocLabels>
</RibbonDiffXml>
Zip your solution and import it. Now you should be able to see attachment button in your custom entity under action group like below
Enjoy!!
make sure to rate this post if you like it

Like
Report
*This post is locked for comments