To achieve this requirement in a system like ServiceNow, 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:
-
Create a server-side script include that can be called from the client side (e.g., by the custom email client script). This script include would perform the actual query to retrieve users based on the selected company.
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'
};
4. 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: The specifics of implementing these steps can vary based on the platform's capabilities and the details of your requirements. If your platform is ServiceNow, for instance, there might be platform-specific APIs or more efficient methods to achieve similar outcomes, and platform updates could offer new features or mechanisms to handle such customizations more naturally. Always consider consulting platform documentation and community forums for the latest best practices and capabilities.
Testing and Roles
Ensure thorough testing, especially considering different roles and permissions, to confirm that the solution works as expected for all potential users.
Remember to consider the user experience and clarify to users why they might not see all the usual recipient options they expect if their company field doesn't match.
Given the custom nature of this solution, ongoing maintenance and adaptability to platform updates or changes in requirements should also be planned for.