Guest Name being populated for some records
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
yesterday
Hello everyone,
I have an inbound action for the guest emails to create a HR Case.
The inbound action is the following:
(function runAction( /*GlideRecord*/ current, /*GlideRecord*/ event, /*EmailWrapper*/ email, /*ScopedEmailLogger*/ logger, /*EmailClassifier*/ classifier) {
var usr = new GlideRecord('sys_user');
usr.get(gs.getUserID());
var guestTEST = gs.getProperty('sn_hr_core.inbound.guest.test');
var guest = gs.getProperty('sn_hr_core.inbound.guest');
//Get OpCo
var opco = new sn_hr_core.hr_ParentOpco().getOpco(gs.getUserID());
//Get active HR Profile
var hrProfileActive = new sn_hr_core.hr_Profile_Query().userHasProfile(gs.getUserID());
var senderMail = email.from;
//Set all basic HR fields
if (gs.getUserID() != guest && opco == "Testing opco" && hrProfileActive == true) {
gs.eventQueue('sn_hr_core.hr.reply.email.test', null, recipientMail, senderMail);
logger.log(" Sender (" + senderMail + ") is already present in the HR Services therefore hr query is not created");
current.setAbortAction(true);
return;
} else {
if (gs.getUserID() != guest) {
current.watch_list = gs.getUserID();
}
var session = gs.getSession();
session.impersonate(guestTEST);
// Core email rules assign "Guest" if the from email does not match a user.
// In this case, check the HR profile personal email, and reassing the case to that user.
var profile;
current.opened_by = guestTEST;
current.opened_for = guestTEST;
var bodyText = email.body_text;
if (!bodyText)
bodyText = email.body_html;
var recipientMail = email.recipients;
current.work_notes = "HR Case created by email:\n\nReceived from: " + email.origemail + "\n\n" + email.subject + "\n\n" + bodyText;
current.description = bodyText;
current.u_sender_email = email.origemail;
}
current.subject_person = current.opened_for;
var newId = current.sys_id;
gs.eventQueue('sn_hr_core_case.email.creation', current, newId, email.from);
})(current, event, email, logger, classifier);
The issue here is: I have a field called 'u_guest_name' that sometimes is being populated and sometimes is not.
Does someone know why is this happening?
Thanks!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
yesterday
hi @rafas_10 ,
One thing to check is your use of current.setAbortAction(true) in the inbound action.
When setAbortAction(true) is executed, the record insert is stopped immediately. This means that any before-insert Business Rules, HR Core logic, or dictionary defaults that normally populate fields (like u_guest_name) will not run. As a result, depending on whether this condition is met, the field may sometimes be populated and sometimes not.
If you need u_guest_name to be consistent, the safest approach is to explicitly set it in the inbound action before aborting or avoid aborting the insert if downstream logic is required.
Thanks, and if this helps, please mark the comment as Helpful so others with the same issue can find it more easily. 😊
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
yesterday
your inbound action script is not populating that field "u_guest_name" as there is no line for that.
Seems some other custom logic is populating and that has an issue.
💡 If my response helped, please mark it as correct ✅ and close the thread 🔒— this helps future readers find the solution faster! 🙏
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
yesterday
Hi @rafas_10
After checking the inbound action, I noticed that u_guest_name is never explicitly populated in the script.
The field gets filled only when ServiceNow is able to extract a sender display name from the inbound email. For guest emails, this depends on the email format:
Emails with a display name (e.g., John Doe <john.doe@gmail.com>) → u_guest_name is populated.
Emails with only an email address → no sender name → field remains empty.
So the behavior is expected and driven by email headers, not by the inbound action logic.
To make it consistent, we can add a small fallback to populate u_guest_name using the sender name or email address.
(function runAction( /*GlideRecord*/ current, /*GlideRecord*/ event, /*EmailWrapper*/ email, /*ScopedEmailLogger*/ logger, /*EmailClassifier*/ classifier) {
var usr = new GlideRecord('sys_user');
usr.get(gs.getUserID());
var guestTEST = gs.getProperty('sn_hr_core.inbound.guest.test');
var guest = gs.getProperty('sn_hr_core.inbound.guest');
//Get OpCo
var opco = new sn_hr_core.hr_ParentOpco().getOpco(gs.getUserID());
//Get active HR Profile
var hrProfileActive = new sn_hr_core.hr_Profile_Query().userHasProfile(gs.getUserID());
var senderMail = email.from;
//Set all basic HR fields
if (gs.getUserID() != guest && opco == "Testing opco" && hrProfileActive == true) {
gs.eventQueue('sn_hr_core.hr.reply.email.test', null, recipientMail, senderMail);
logger.log(" Sender (" + senderMail + ") is already present in the HR Services therefore hr query is not created");
current.setAbortAction(true);
return;
} else {
if (gs.getUserID() != guest) {
current.watch_list = gs.getUserID();
}
var session = gs.getSession();
session.impersonate(guestTEST);
current.opened_by = guestTEST;
current.opened_for = guestTEST;
var bodyText = email.body_text;
if (!bodyText)
bodyText = email.body_html;
var recipientMail = email.recipients;
current.work_notes = "HR Case created by email:\n\nReceived from: " + email.origemail + "\n\n" + email.subject + "\n\n" + bodyText;
current.description = bodyText;
current.u_sender_email = email.origemail;
// Fallback logic added for consistent guest name population
if (!current.u_guest_name) {
current.u_guest_name = email.from_name || email.from;
}
}
current.subject_person = current.opened_for;
var newId = current.sys_id;
gs.eventQueue('sn_hr_core_case.email.creation', current, newId, email.from);
})(current, event, email, logger, classifier);If you find this reply as useful please mark it as helpful and accept my solution😇
