inbound action script is not working.
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-02-2024 07:34 AM
I have written below script but it is not working request has been created but not going to proper catalog item, I have put currect sys_ID. kindly let me know what is issue in below script.
(function runAction( /*GlideRecord*/ current, /*GlideRecord*/ event, /*EmailWrapper*/ email, /*ScopedEmailLogger*/ logger, /*EmailClassifier*/ classifier) {
// Implement email action here
createRequest();
function createRequest() {
var userSysid;
var reqgroup;
var plant;
var sub = email.subject.toString().toLowerCase();
var urg = sub.indexOf('urg');
gs.info(urg + " is the urgency");
var gr = new GlideRecord('sys_user');
gr.addQuery('email', email.from);
gr.query();
if (gr.next()) {
userSysid = gr.sys_id;
}
var cart = new Cart();
// add in cart, substitute your catalog item sys_id
var item = cart.addItem('49dd78a3db427c50eeb8026dd3961902');
if (!item) {
gs.error('Failed to add catalog item to cart');
} else {
gs.info('Catalog item added to cart: ' + item);
}
cart.setVariable(item, 'description', email.body_html);
gs.log("test");
cart.setVariable(item, 'contact_type', 'email');
cart.setVariable(item, 'sub_heads','nurture_business');
cart.setVariable(item,'sub_activities_vs','depot_update');
cart.setVariable(item, 'subject', email.subject);
cart.setVariable(item, 'head_email', email.recipients);
var rc = cart.placeOrder();
//gs.info('ASK HR : - '+ rc.sys_id);
// update shortdescription as Subject in RITM & task and set Requested group in RITM
var ritm = new GlideRecord('sc_req_item');
ritm.addQuery('request', rc.sys_id);
ritm.query();
if (ritm.next()) {
if (urg == -1) {
ritm.short_description = email.subject;
} else {
ritm.short_description = 'URGENT ' + email.subject;
}
ritm.watch_list = email.copied;
ritm.update();
}
var sctask = new GlideRecord('pm_project_task');
sctask.addQuery('parent', ritm.sys_id);
sctask.query();
if (sctask.next()) {
if (urg == -1) {
ritm.short_description = email.subject;
} else {
ritm.short_description = 'URGENT ' + email.subject;
}
sctask.watch_list = email.copied;
sctask.update();
}
// add attachment to RITM
var emailRec = new GlideRecord("sys_email");
emailRec.addQuery("uid", email.uid);
emailRec.orderByDesc("sys_created_on");
emailRec.query();
if (emailRec.next()) {
GlideSysAttachment.copy("sys_email", emailRec.sys_id, "sc_req_item", ritm.sys_id);
}
}
})(current, event, email, logger, classifier);
1 REPLY 1
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-03-2024 01:22 AM
Hello @keval3,
Please refer to the link below:
https://www.servicenow.com/community/developer-forum/inbound-action-not-working/m-p/2677126
If it is helpful, please mark it as helpful and accept the correct solution. In future it might be helpful to someone by refer to this solution.
Thanks & Regards,
Abbas Shaik