Sending Email Restriction
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-22-2024 11:37 PM
I have a requirement where we need to restrict 'Compose Email' UI Action for TO/CC/BCC users, based on the Company selected on Ticket .
For eg: On INC00001, I have a field called Company which is "ABC PVT" and now, when a user From 'ABC Pvt' company clicks on Compose email, he should be able to see users in TO/CC/BCC from 'ABC PVT' company only.
How can we achieve this?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-23-2024 12:12 AM
Hi @Community Alums
To achieve this requirement, you would need to customize the “Compose Email” UI action to filter the TO/CC/BCC recipient list based on the Company selected on the Ticket (e.g., an Incident). This involves a combination of client-side scripting (for UI actions) and server-side scripting (to query and filter users based on companies). Since direct manipulation of the out-of-the-box Compose Email interface to restrict the address book dynamically based on the company selection might be limited purely through configuration, consider a custom solution approach:
1. Custom Scripted UI Action:
- Step 1: Clone the existing “Compose Email” UI action or create a new one if you prefer to keep the original intact. This is essential to preserve original functionality elsewhere or to easily revert changes.
- Step 2: Modify the script in the UI action to include a reference to the current company and pass this information to the email client script or email form.
2. Custom Email Client Script:
You may need to create a custom email client script (if the platform supports or leverages email client scripts for customization, like ServiceNow) that pre-filters the TO/CC/BCC fields based on the user’s company.
- This script would be responsible for:
- Capturing the company ID or name from the Incident record (or whichever ticket form you’re dealing with).
- Filtering the address book or user list dynamically based on the company that matches the company in the ticket form. This can be done through AJAX calls to the server to fetch users belonging to the specified company and then populating the recipient fields accordingly.
3. Server-side Filtering:
var UsersFromCompany = Class.create();
UsersFromCompany.prototype = {
initialize: function() {
},
getUsersByCompanyId: function(companyId) {
var userData = [];
var userGr = new GlideRecord('sys_user');
userGr.addQuery('company', companyId);
userGr.query();
while (userGr.next()) {
// Simplified user data extraction: Implement based on actual field names and desired data
userData.push({
sys_id: userGr.getValue('sys_id'),
name: userGr.getValue('name'),
email: userGr.getValue('email')
});
}
return userData;
},
type: 'UsersFromCompany'
};
Adjusting the Email Form on the Client-Side:
- Your custom email client script would call this server-side script include’s method, passing the company ID, to get the filtered list of users. Once retrieved, it should dynamically adjust the TO/CC/BCC fields’ selection options to limit them to the users from the specified company.
- Implement client-side logic to handle the population of TO/CC/BCC fields with the response.
Note: Please Mark this Helpful and Accepted Solution. If this Helps you to understand. This will help us a lot.
Thanks & Regards
Deepak Sharma
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-26-2024 03:09 AM
Hi, It was achievable with Recipient Qualifiers. But I am facing one issue, If I type someone's whole email address for example, a user's email address who belongs to another company, then it is accepting this value.