{"id":735,"date":"2012-05-22T08:54:34","date_gmt":"2012-05-22T08:54:34","guid":{"rendered":"http:\/\/mahenderpal.wordpress.com\/?p=735"},"modified":"2012-05-22T08:54:34","modified_gmt":"2012-05-22T08:54:34","slug":"adding-attach-file-button-on-custom-activity-type-entity","status":"publish","type":"post","link":"https:\/\/himbap.com\/blog\/?p=735","title":{"rendered":"Adding Attach File button on Custom Activity  Type Entity"},"content":{"rendered":"<p>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\u2019t 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 \ud83d\ude42<\/p>\n<p>To create custom Attach File button we need<\/p>\n<ol>\n<li>A Webresource to form notes URL.<\/li>\n<li>We need Attach File image to show it in custom Ribbon button.<\/li>\n<li>We need to create custom Ribbon Button.<\/li>\n<\/ol>\n<p>\u00a0Let\u2019s first create webresource to open notes dialog.<\/p>\n<p>Let\u2019s first create a solution and add our custom activity to that solution. Once entity is added create a new web resource let\u2019s say <strong>Notes.js<\/strong> and add below function to that webresourc<\/p>\n<p>function FileAttachment()<\/p>\n<p>{<\/p>\n<p>var EntityID =Xrm.Page.data.entity.getId(); \/\/ to get entity id<\/p>\n<p>var ServicerURL=Xrm.Page.context.getServerUrl(); \/\/ to get server url<\/p>\n<p>var NotesURL=ServicerURL+&#8221;\/notes\/edit.aspx?hideDesc=1&amp;pId=&#8221;+ EntityID +&#8221;&amp;pType=&#8221;;<\/p>\n<p>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<\/p>\n<p>var features = &#8216;copyhistory=no,top=110,left=280,width=600,height=30&#8217;;<\/p>\n<p>openStdWin(NotesURL +etc,&#8221;&#8221;,features);<\/p>\n<p>}<\/p>\n<p>Save and close webresourc and publish it.<\/p>\n<p>Let\u2019s create a .png\u00a0 image webresource to store image for attachment ribbon button. Follow below steps to create image webresource<\/p>\n<ol>\n<li>Navigate to Solution-&gt;Webresourc and click New<\/li>\n<li>Enter below information<\/li>\n<\/ol>\n<ul>\n<li>Name: AddAttachment_16.png<\/li>\n<li>Display Name: AddAttachment_16<\/li>\n<li>Type: PNG format<\/li>\n<li>Language: English<\/li>\n<\/ul>\n<p>** we need to upload attachment_16.png, You can find this image\u00a0for attachment in <strong>sdkresourcesimagesribbon<\/strong> folder.<\/p>\n<p>we need to follow same steps to create webresourc for attachment_32.png image.<\/p>\n<p>Now we have our web resources ready so let\u2019s 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:<\/p>\n<p>\u00a0 &lt;RibbonDiffXml&gt;<\/p>\n<p>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 &lt;CustomActions&gt;<\/p>\n<p>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 &lt;CustomAction Id=&#8221;MYDEMO.Form.new_CustomActivity.MainTab.Actions.attachment.CustomAction&#8221; Location=&#8221;Mscrm.Form.new_CustomActivity.MainTab.Actions.Controls._children&#8221; Sequence=&#8221;41&#8243;&gt;<\/p>\n<p>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 &lt;CommandUIDefinition&gt;<\/p>\n<p>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 &lt;Button Id=&#8221;MyDemo.Form.new_CustomActivity.MainTab.Actions.attachment&#8221; Command=&#8221;MYDEMO.Form.new_CustomActivity.MainTab.Actions.attachment.Command&#8221; Sequence=&#8221;29&#8243; ToolTipTitle=&#8221;$LocLabels:MYDEMO.Form.new_CustomActivity.MainTab.Actions.attachment.LabelText&#8221; LabelText=&#8221;$LocLabels:MYDEMO.Form.new_CustomActivity.MainTab.Actions.attachment.LabelText&#8221; ToolTipDescription=&#8221;$LocLabels:MYDEMO.Form.new_CustomActivity.MainTab.Actions.attachment.Description&#8221; TemplateAlias=&#8221;o1&#8243; Image16by16=&#8221;$webresource:MyDemo_Attachment_16.png&#8221; Image32by32=&#8221;$webresource:MyDemo_Attachment_32.png&#8221; \/&gt;<\/p>\n<p>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 &lt;\/CommandUIDefinition&gt;<\/p>\n<p>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 &lt;\/CustomAction&gt;<\/p>\n<p>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 &lt;\/CustomActions&gt;<\/p>\n<p>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 &lt;Templates&gt;<\/p>\n<p>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 &lt;RibbonTemplates Id=&#8221;Mscrm.Templates&#8221;&gt;&lt;\/RibbonTemplates&gt;<\/p>\n<p>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 &lt;\/Templates&gt;<\/p>\n<p>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 &lt;CommandDefinitions&gt;<\/p>\n<p>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 &lt;CommandDefinition Id=&#8221;MYDEMO.Form.new_CustomActivity.MainTab.Actions.attachment.Command&#8221;&gt;<\/p>\n<p>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 &lt;EnableRules&gt;<\/p>\n<p>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 &lt;EnableRule Id=&#8221;MYDEMO.Form.new_CustomActivity.MainTab.Actions.attachment.Command.EnableRule.FormStateRule&#8221; \/&gt;<\/p>\n<p>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 &lt;\/EnableRules&gt;<\/p>\n<p>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 &lt;DisplayRules \/&gt;<\/p>\n<p>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 &lt;Actions&gt;<\/p>\n<p>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 &lt;JavaScriptFunction FunctionName=&#8221;FileAttachment&#8221; Library=&#8221;$webresource:MyDemo_Attachment.js&#8221; \/&gt;<\/p>\n<p>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 &lt;\/Actions&gt;<\/p>\n<p>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 &lt;\/CommandDefinition&gt;<\/p>\n<p>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 &lt;\/CommandDefinitions&gt;<\/p>\n<p>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 &lt;RuleDefinitions&gt;<\/p>\n<p>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 &lt;TabDisplayRules \/&gt;<\/p>\n<p>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 &lt;DisplayRules \/&gt;<\/p>\n<p>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 &lt;EnableRules&gt;<\/p>\n<p>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 &lt;EnableRule Id=&#8221;MYDEMO.Form.new_CustomActivity.MainTab.Actions.attachment.Command.EnableRule.FormStateRule&#8221;&gt;<\/p>\n<p>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 &lt;FormStateRule State=&#8221;Existing&#8221; Default=&#8221;false&#8221; InvertResult=&#8221;false&#8221; \/&gt;<\/p>\n<p>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 &lt;\/EnableRule&gt;<\/p>\n<p>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 &lt;\/EnableRules&gt;<\/p>\n<p>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 &lt;\/RuleDefinitions&gt;<\/p>\n<p>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 &lt;LocLabels&gt;<\/p>\n<p>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 &lt;LocLabel Id=&#8221;MYDEMO.Form.new_CustomActivity.MainTab.Actions.attachment.Description&#8221;&gt;<\/p>\n<p>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 &lt;Titles&gt;<\/p>\n<p>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 &lt;Title languagecode=&#8221;1033&#8243; description=&#8221;attachment Description&#8221; \/&gt;<\/p>\n<p>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 &lt;\/Titles&gt;<\/p>\n<p>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 &lt;\/LocLabel&gt;<\/p>\n<p>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 &lt;LocLabel Id=&#8221;MYDEMO.Form.new_CustomActivity.MainTab.Actions.attachment.LabelText&#8221;&gt;<\/p>\n<p>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 &lt;Titles&gt;<\/p>\n<p>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 &lt;Title languagecode=&#8221;1033&#8243; description=&#8221;Attach File&#8221; \/&gt;<\/p>\n<p>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 &lt;\/Titles&gt;<\/p>\n<p>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 &lt;\/LocLabel&gt;<\/p>\n<p>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 &lt;\/LocLabels&gt;<\/p>\n<p>\u00a0\u00a0\u00a0\u00a0\u00a0 &lt;\/RibbonDiffXml&gt;<\/p>\n<p>Zip your solution and import it. Now you should be able to see attachment button in your custom entity under action group like below<\/p>\n<p><a href=\"http:\/\/mahenderpal.files.wordpress.com\/2012\/05\/attbutton.png\"><img decoding=\"async\" loading=\"lazy\" class=\"aligncenter size-full wp-image-737\" title=\"attbutton\" src=\"http:\/\/mahenderpal.files.wordpress.com\/2012\/05\/attbutton.png\" alt=\"\" width=\"109\" height=\"90\" \/><\/a><\/p>\n<p>\u00a0Enjoy!!<\/p>\n<p>make sure to rate this post if you like it \ud83d\ude42<\/p>\n","protected":false},"excerpt":{"rendered":"<p>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\u2019t 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&#8230; <a href=\"https:\/\/himbap.com\/blog\/?p=735\">Read more &raquo;<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[5,19],"tags":[],"_links":{"self":[{"href":"https:\/\/himbap.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/735"}],"collection":[{"href":"https:\/\/himbap.com\/blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/himbap.com\/blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/himbap.com\/blog\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/himbap.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=735"}],"version-history":[{"count":0,"href":"https:\/\/himbap.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/735\/revisions"}],"wp:attachment":[{"href":"https:\/\/himbap.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=735"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/himbap.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=735"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/himbap.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=735"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}