BR on the sys_email table to create emails received as attachments to RITM.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-23-2024 01:49 AM
I created this before-insert Business rule in the 'sys_email' table to add emails received as attachments to RITM. However, debug returns the error message 'org.mozilla.javascript.Evaluator'.Exception: Cannot find the method com.glide.ui.SysAttachment.write(java.lang.String,org.mozilla.javascript.ConsString,string,org.mozilla.javascript.ConsString).'
What might have gone wrong?
(function executeRule(current, previous /*null when async*/ ) {
var sysId = current.instance;
var grB = new GlideRecord("sc_req_item");
grB.addQuery('sys_id', sysId);
grB.query();
if (grB.next()) {
gs.info("Debug: " + sysId); //This return a correct sysId
if (grB.cat_item == '3ae423dkfy89s7akla1243') {
var attachment = new GlideSysAttachment();
var fileName = current.subject + '.eml';
var contentType = 'application/octet-stream';
var content = current.content_type + "\n" + current.headers + "\n\n\n\n" + current.body_text;
var agr = attachment.write(sysId, fileName, contentType, content);
gs.info("Debug: The attachment sys_id is: " + agr);
//grB.insert();
}
}
})(current, previous);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-23-2024 04:08 AM
seems your BR is running multiple times
Why not handle this in the inbound email action script itself and add your complete email as attachment to target record?
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
‎12-23-2024 04:22 AM
Hello Ankur,
I have the inbound action has a line in for GlideSysAttachment.copy, adding the
(function runAction( /*GlideRecord*/ current, /*GlideRecord*/ event, /*EmailWrapper*/ email, /*ScopedEmailLogger*/ logger, /*EmailClassifier*/ classifier) {
var cartId = GlideGuid.generate(null);
var cart = new Cart(cartId);
var subject = email.subject;
var item;
item = cart.addItem('3ae423dkfy89s7akla1243');
cart.setVariable(item, 'description', email.body_text);
var rc = cart.placeOrder();
current.requested_for = gs.getUserID();
var gr = new GlideRecord("sc_req_item");
if (gr.get("request", rc.sys_id)) {
gr.setValue('contact_type', 'email');
gr.update();
sys_email.target_table = "sc_req_item";
sys_email.instance = gr.sys_id;
GlideSysAttachment.copy('sys_email', sys_email.sys_id, 'sc_req_item', gr.sys_id);
var fileName = email.subject + '.eml';
var contentType = 'application/octet-stream';
var content = email.content_type + "\n" + email.headers + "\n\n\n\n" + email.body_text;
GlideSysAttachment.write(gr.sys_id, fileName, contentType, content);
}
current.update;
})(current, event, email, logger, classifier);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-23-2024 04:40 AM
update line as this -> 1st parameter should be GlideRecord object and not record sysId
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
‎12-23-2024 04:52 AM
Thanks Ankur,
updated the line as suggest. i even tried added another line after
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-23-2024 10:22 PM
are you sure there is RITM associated to that REQ when your script runs?
what debugging have you done so far by adding logs?
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader