- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-18-2023 09:50 AM
I feel like I'm going insane. I have a script running on an Inbound Email Action that reads variables in the email body and creates a request for that person. I've added some debug so I can watch the script execute in the system log to try and determine where things are going wrong, but it seems the script is terminating very early on in the script. I can't figure out why the script is stopping at this point, it's a very simple GlideRecord query that completes just fine when I test in background scripts.
Can you spot anything wrong or is there something outside this Inbound Email Action that I'm not thinking of?
Any help is appreciated!
The script seems to be stopping after line 10
gs.log('USER : ' + user, 'intranet_email');
Here's the full script
(function runAction(/*GlideRecord*/ current, /*GlideRecord*/ event, /*EmailWrapper*/ email, /*ScopedEmailLogger*/ logger, /*EmailClassifier*/ classifier) {
// Implement email action here
var url = email.body.requested_resource; //Extract requested URL from email body variable 'Requested resource'
var user = email.body.requested_by; //Extract requested for from email body variable 'Requested by'
var regex = /([a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,})/; //Extract user's email address from HTML with regex
var matches = regex.exec(user);
user = matches[1];
gs.log('URL : ' + url, 'intranet_email');
gs.log('USER : ' + user, 'intranet_email');
var gr = new GlideRecord();
gr.get('email', user);
gs.log('GR USER : ' + gr.name, 'intranet_email');
var cart = new sn_sc.CartJS();
var item = {
'sysparm_id': 'eba12642db967600e44c70d9af96198b',
'sysparm_quantity': '1',
'variables': {
'opened_by': '6816f79cc0a8016401c5a33be04be441',
'requested_for': '',
'location': '',
'department': '',
'title': '',
'request_type': 'access_change',
'url': '',
'access_level': 'read',
'additional_information': ''
}
};
gs.log('EMPTY ITEM : ' + JSON.stringify(item), 'intranet_email');
item.variables.requested_for = gr.sys_id.getValue();
item.variables.location = gr.location.getValue();
item.variables.department = gr.department.getValue();
item.variables.title = gr.title.getValue();
item.variables.url = url;
item.variables.additional_information = 'This request was generated through an automatic process. The indicated access level may be incorrect.\n\nEmail subject: ' + email.subject;
gs.log('POPULATED ITEM : ' + JSON.stringify(item), 'intranet_email');
cart.addToCart(item);
var checkoutInfo = cart.checkoutCart();
gs.log('REQ : ' + checkoutInfo.request_id, 'intranet_email');
var cartId = cart.getCartID();
gs.log('EMPTYING CART : ' + cartId, 'intranet_email');
cart.empty(cartId);
gs.log('DONE', 'intranet_email');
})(current, event, email, logger, classifier);
And here's the log output I'm getting when I run the script
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-18-2023 10:38 AM - edited 12-18-2023 10:41 AM
Hi @Oliver Anderson
In the below line of code, you should pass the table name- (sys_user).
var gr = new GlideRecord();
Also there is syntax issue in below line of code-
item.variables.requested_for = gr.sys_id.getValue();// it should be gr.sys_id+"";
item.variables.location = gr.location+"";
item.variables.department = gr.department+"";
item.variables.title = gr.title+"";
Thanks and Regards,
Saurabh Gupta
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-18-2023 10:38 AM - edited 12-18-2023 10:41 AM
Hi @Oliver Anderson
In the below line of code, you should pass the table name- (sys_user).
var gr = new GlideRecord();
Also there is syntax issue in below line of code-
item.variables.requested_for = gr.sys_id.getValue();// it should be gr.sys_id+"";
item.variables.location = gr.location+"";
item.variables.department = gr.department+"";
item.variables.title = gr.title+"";
Thanks and Regards,
Saurabh Gupta
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-18-2023 10:54 AM
Ahhhhhhh I forgot the table name. Thank you so much, I don't know how I missed that, I read that line over about 20 times.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-18-2023 10:56 AM
Hi @Oliver Anderson
At times it happens, that's why second eye is important.
Thanks and Regards,
Saurabh Gupta