Need help with an email inbound action script
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
I am trying to create an inbound action. It should take the username from the subject line and submit a Catalog Item in the name of that user. It should check the u_employee_type field of the user record. If the value is Employee, it should generate Catalog item b150ee90879bb410a2efbaa6cebb3573. if not, generate catalog item 0d4d616f1b1bf0502cc987b3604bcbef. This is the script I have so far. I've run it through chatgpt and NowAssist several times, but I can't get it to work. I would appreciate any help.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
2 weeks ago
Bump
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
2 weeks ago
are you still looking for answer to this?
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
2 weeks ago
@Ankur Bawiskar Yes I am
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
2 weeks ago
this should work provided you are extracting the correct name and provided the inbound action is getting processed
var subject = email.subject;
var usernameMatch = subject.match(/Pending Termination:\s*(\w+)/);
if (!usernameMatch || usernameMatch.length < 2) {
gs.info("Inbound Email Action: Username not found in subject.");
return;
}
var username = usernameMatch[1];
gs.info("Inbound Email Action: Found username - " + username);
// Look up the user record
var userGR = new GlideRecord('sys_user');
userGR.addQuery('user_name', username);
userGR.query();
if (!userGR.next()) {
gs.info("Inbound Email Action: User not found - " + username);
return;
}
// Choose the catalog item based on employee type
var catalogItemId = (userGR.u_employee_type == 'Employee') ?
'b150ee90879bb410a2efbaa6cebb3573' :
'0d4d616f1b1bf0502cc987b3604bcbef';
var cart = new sn_sc.CartJS();
cart.setRequestedFor(userGR.getUniqueValue());
var item = {
'sysparm_id': catalogItemId,
'sysparm_quantity': '1',
'variables': {
'user': '7282abf03710200044e0bfc8bcbe5d03',
}
};
var cartDetails = cart.addToCart(item);
var checkoutInfo = cart.checkoutCart();
gs.info("Inbound Email Action: Catalog item " + catalogItemId + " requested for user " + username);
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
2 weeks ago
@Ankur Bawiskar still got: Skipping script 'Auto Offboarding', a suitable GlideRecord not found