Override the OOB(Out-Of-Box) Send Email Ribbon
Introduction:
Sometimes, we may need to override the OOB(Out-of-Box) ribbon operation or add additional checking logic to ensure certain conditions are met.
Scenario:
For instance, there is a lot of sensitive information in the email. Before sending the email, you must get approval from your manager.
If the Approval Status is not Approved, an alert message will be displayed saying “Sending emails is currently not allowed. Please check with your manager for confirmation before attempting to send”.
The solution is presented in a step-by-step manner
Step 1: Open Ribbon Workben in the XRM Toolbox and select the solution that contains the Email entity.
Step 2: Copy and Paste the OOB SEND Ribbon
A new Ribbon Send will be added
Step 3: Hide the OOB Ribbon
Step 4: Modify the newly added SEND Ribbon
Keep all the copied configurations, we just need to change the Command to our custom JS function
Step 4: Binding to your custom Function
Source Code
"use strict"; // A namespace defined for the sample code // As a best practice, you should always define // a unique namespace for your libraries if (typeof (TestNameSpace) === "undefined" || TestNameSpace === null) { var TestNameSpace = {}; } if (typeof (TestNameSpace.Email) === "undefined") { TestNameSpace.Email = {}; } //a unique namespace for your Entity libraries TestNameSpace.Email = { //global variable ApprovalStatusCode: { Pending: 900000000, Approved: 900000001, Rejected: 900000002 }, // Custom Send Ribbon Function CustomSendCommand: function (primaryControl) { //Add your custom logic here - begin var approvalStatus = primaryControl.getAttribute("test_approvalstatus").getValue(); if( approvalStatus != this.ApprovalStatusCode.Approved) { var msg = "Sending emails is currently not allowed. Please check with your manager for confirmation before attempting to send"; Xrm.Navigation.openErrorDialog({ message: msg }); } //End else { //The Out-of-Box function Activities.EmailCommands.send(primaryControl); } } }
Step 5: Publishing Solution
Step 6: Testing
The End
*This post is locked for comments