- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-21-2025 08:51 AM - edited 04-23-2025 01:15 AM
Hi All,
Above is a screenshot of a HR case created from an Inbound email action.
I need to display an error message at the top, above the info message that you see in the screenshot, whenever the sender's email domain(i.e. the person who sent the email via which the case got created in SNOW) isn't among the whitelisted ones(@abc.com , @xyz.com for egs), mentioning something like 'This email isn't from a trusted domain. Kindly proceed with caution.'
Can someone please help me achieve this. Thanks!
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-28-2025 08:35 AM
Hi Ankur,
I have created a custom field for the form, populated the sender email from the inbound action by setting the field's current value with email.origemail, and then used your script, it worked as expected.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-21-2025 09:21 AM
it's an easy onload client script to add color and show message
something like this if the field is editable
function onLoad() {
// Allowed domains
var allowedDomains = ['@abc.com', '@xyz.com'];
// Get the email origination field value
var emailOrigination = g_form.getValue('email_originationField');
if (emailOrigination) {
// Extract the domain from the email
var emailDomain = emailOrigination.substring(emailOrigination.indexOf('@'));
// Check if the domain is not in the allowed domains list
if (!allowedDomains.includes(emailDomain)) {
// Highlight the field in orange
var control = g_form.getControl('email_originationField');
control.style.backgroundColor = "orange"; // to set the background color
// Display an error message
g_form.addErrorMessage("This email isn't from a trusted domain. Kindly proceed with caution.");
}
}
}
Something like this if field is readonly
function onLoad() {
// Allowed domains
var allowedDomains = ['@abc.com', '@xyz.com'];
// Get the email origination field value
var emailOrigination = g_form.getValue('email_originationField');
if (emailOrigination) {
// Extract the domain from the email
var emailDomain = emailOrigination.substring(emailOrigination.indexOf('@'));
// Check if the domain is not in the allowed domains list
if (!allowedDomains.includes(emailDomain)) {
// Highlight the field in orange
var table = g_form.getTableName();
var fieldName = 'email_originationField';
var ctrl = g_form.getControl(table + '.' + fieldName);
if (ctrl['nodeName'] != 'SELECT') {
ctrl = g_form.getControl('sys_readonly.' + table + '.' + fieldName);
ctrl.style.backgroundColor = 'orange';
}
// Display an error message
g_form.addErrorMessage("This email isn't from a trusted domain. Kindly proceed with caution.");
}
}
}
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-21-2025 09:18 PM
Hope you are doing good.
Did my reply answer your question?
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-21-2025 10:34 PM
Thank you for marking my response as helpful.
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-23-2025 01:21 AM
Thanks Ankur.
However, I just got to know that the ' Email Origination' field isnt really the sender's email address, but actually the recipient email address. So, I don't quite have the sender's email address in the form.
I have updated my requirement in the question, where I would just need to print that error message, but now since I dont have the senders email address in the form, can you please help me achieve this. Thanks!