Skip to main content

Notifications

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.

5025.pastedimage1683359952111v1.png

Step 2:  Copy and Paste the OOB SEND Ribbon

2728.pastedimage1683360100371v2.png

A new Ribbon Send will be added

1715.pastedimage1683360217911v3.png

Step 3: Hide the OOB Ribbon

1070.pastedimage1683360272346v4.png

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

8322.pastedimage1683360871293v5.png

Step 4: Binding to your custom Function

6874.pastedimage1683361613181v6.png

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

1777.pastedimage1683361797655v7.png

Step 6: Testing 

8228.pastedimage1683362947529v8.png

The End

Comments

*This post is locked for comments