Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
yesterday
(function runAction(/*GlideRecord*/ current, /*GlideRecord*/ event, /*EmailWrapper*/ email, /*ScopedEmailLogger*/ logger, /*EmailClassifier*/ classifier) {
// Implement email action here
var cartID=GlideGuid.generate(null);
var cart= new Cart(cartID);
var item= cart.addItem('158edf4a2bacfe10eacaf2a6d391bf51');
//cart.setVariable(item,'short_description','test short');
cart.setVariable(item,' requested_for',gs.getUserID());
cart.setVariable(item,'short_description',email.subject);
cart.setVariable(item,'subject','This request created when the caller sended email for creating a request');
cart.setVariable(item,'description',email.body_text);
var rc=cart.placeOrder();
var ritm=new GlideRecord("sc_req_item");
ritm.addQuery('request',rc.sys_id);
ritm.query();
if(ritm.next())
{
ritm.short_description = email.subject.toString();
ritm.contact_type="email";
ritm.update();
}
})(current, event, email, logger, classifier);
This is the code . Can you pls help me
This is the code . Can you pls help me
Solved! Go to Solution.
1 ACCEPTED SOLUTION
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
4 hours ago
So as per your information the RITM is getting created and the incoming file to email should get copied to RITM
please update code as this
var ritm=new GlideRecord("sc_req_item");
ritm.addQuery('request',rc.sys_id);
ritm.query();
if(ritm.next())
{
ritm.short_description = email.subject.toString();
ritm.contact_type="email";
ritm.update();
new GlideSysAttachment().copy('sys_email', sys_email.sys_id, 'sc_req_item', ritm.sys_id);
}
💡 If my response helped, please mark it as correct ✅ and close the thread 🔒— this helps future readers find the solution faster! 🙏
Regards,
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
6 REPLIES 6
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
5 hours ago
HI @NeethuB
i have updated few lines , can you try this code -
(function runAction(current, event, email, logger, classifier) {
try {
var cartID = GlideGuid.generate(null);
var cart = new Cart(cartID);
// Add Catalog Item
var item = cart.addItem('158edf4a2bacfe10eacaf2a6d391bf51');
// Set variables (ensure these exist in the catalog item)
cart.setVariable(item, 'requested_for', gs.getUserID());
cart.setVariable(item, 'short_description', email.subject || 'Email Request');
cart.setVariable(item, 'subject', 'Request created from email');
cart.setVariable(item, 'description', email.body_text || 'No description provided');
// Place order
var rc = cart.placeOrder();
if (!rc) {
logger.error('Failed to place order from email.');
return;
}
// Update RITM
var ritm = new GlideRecord('sc_req_item');
ritm.addQuery('request', rc.sys_id);
ritm.query();
if (ritm.next()) {
ritm.short_description = email.subject.toString();
ritm.contact_type = 'email';
ritm.update();
}
logger.info('Request created successfully from email: ' + rc.number);
} catch (e) {
logger.error('Error in email action: ' + e.message);
}
})(current, event, email, logger, classifier);NOTE -
- Validate that the catalog item and variables exist.
- Use gs.getUserID() carefully; if you want the caller from the email, you might need email.origemail or email.from.
- Add logging for success and failure.
- Consider security: only allow certain email domains to create requests.
Thanks,
Rithika.ch
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
4 hours ago
Not working
