Create a custom HTML button in Dynamics 365

Spread the Knowledge...

In this post we will discuss about how to create a custom button in CRM form. Custom HTML button can’t be created using Ribbon workbench. To create a custom HTML button, you need to create a HTML Webresource and add that Webresource in the required entity form.

Follow the below steps to know more about how to create a HTML Webresource.

Step 1:

Navigate to Settings à Customizations >> Customize the System >> Select Web Resources from left Panel >> Click ‘New’.

Fill Name, Display Name, Description, Type, Language etc. in new web resource popup window as mentioned in below screenshot.

Step1 - Create a custom HTML button in Dynamics 365

Step 2:

Click Text Editor button available next to Type field.

Step2.1 - Create a custom HTML button in Dynamics 365

Write the HTML code to create a button in ‘Edit Content’ window as mentioned below.

Step2.2 - Create a custom HTML button in Dynamics 365

Code Snippet

<html><head>    
 <script type="text/javascript">
     function getAccountCategory() {                
         var accountCategory = window.parent.Xrm.Page.getAttribute("new_accountcategory").getValue();
         alert("AccountCategory: "+accountCategory );
     }
     </script>
<meta charset="utf-8">             
</head>
<body> 
    <button onclick="getAccountCategory()">Click to get Account Category</button>
</body></html>

Make sure that after putting the HTML code in Source tab, you are able to see the button in Rich Text tab.

Step2.3 - Create a custom HTML button in Dynamics 365

Step 3:

Click Ok.

Save and Publish the Webresource.

Step 4: To insert a custom button into CRM form.

  • Navigate to Settings >> Customizations >> Customize the system >> Entities >> select required entity (in my case I’m selecting Lead entity.) >> Form >> Open the required form.
  • Select the section where you want to place new custom button.
  • Select Web Resource from Insert tab.
Step4.1 1 - Create a custom HTML button in Dynamics 365
  • Fill the required fields in ‘Add Web Resource’ Pop up.
Step4.2 - Create a custom HTML button in Dynamics 365
  • Click Ok. Save and Publish the changes.
  • Refresh your entity and check the custom button.
  • Popup will come on click of custom button.
Step4.3 - Create a custom HTML button in Dynamics 365

Hope this helps!!!


Spread the Knowledge...