
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-20-2018 11:24 PM
I have seen a few articles, and I may be going about this partially incorrectly. I am trying to create a task record from an Inbound HR Termination email. I don't have it as a catalog item, so thought it would be okay just to create a task record. Everything appears to work correctly but, I can't seem to populate the 'Requested for' field within my Task record. My 'Requested for' field comes from the Request record itself and in this case, I don't have any parents (Request Item or Request). But I am able to manually enter a name into the field on my Task record, so it would seem that I should be to push the 'Sender's' name to the field.
Here are some of the samples I have tried but no success. Any ideas what I am missing, or is it impossible because my Task has no parents?
current.comments = 'Received from: ' + email.origemail + "\n" + "Subject: " + email.subject;
current.short_description = "HR-Term Notice: " + email.subject;
var str = email.body_text.replace(/\n\n/g,"\n"); // \t
current.description = str;
//var sid = gs.createUser(email.from);
//current.request_item.request.requested_for = sid // Fails
//current.requested_for = sid // Fails
//current.request_item.request.requested_for = email.origemail; // Fails
//current.requested_for = email.origemail; // Fails
//current.request_item.request.requested_for = email.origemail; // Fails
//current.requested_for = email.origemail; // Fails
current.assignment_group = 'b60f0c4f0f344700b855f08ce1050e3a'; // Software Development Tools Support
current.priority = 4;
current.setAbortAction(true);
current.insert();
Thank you,
-Wesley
Solved! Go to Solution.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-21-2018 10:31 PM
I think the catalog item is the way to go, since in time you can encourage the HR dept to use the catalog itself.
You will need to use the CartJS API from the Inbound Action, if you're familiar with scripting.
This is the kind of script you will need on your Inbound Action:
var terminationSC = 'SYS_ID OF YOUR CATALOG ITEM';
var cart = new sn_sc.CartJS();
var item =
{
'sysparm_id': terminationSC,
'sysparm_quantity': '1',
};
cart.addToCart(item);
cart.setRequestedFor("94c26ab34f7d130050e5b63ca310c768");
//set the submitOrder output to a variable so we can get the request sys_id
var requestDetails = cart.checkoutCart();
var request = requestDetails.request_id;
//now lets lookup the RITM that was created and add the email subject and body to the additional comments, so you know what to do with it
var gr = new GlideRecord('sc_req_item');
gr.addQuery('request',request);
gr.query();
while(gr.next())
{
gr.comments = email.subject + '\n\n' + email.body_text.replace(/\n\n/g,"\n");
gr.update();
}
I did some brief testing on this - please note that I was always getting a null exception upon the ordering of the item, which seems to stop the GlideRecord lookup. However, the Request and Requested Item were being ordered successfully.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-21-2018 07:09 PM
Hi Wesley,
What is your use case? That emails from HR regarding terminations kick off a ticket for a specific department to action them?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-21-2018 08:37 PM
Hi Jamieimms,
Exactly. I could go with what I have now, just seems a bit off that I don't have a Requested for person (value). I suppose that I could use a different table like Incident. But then it jacks with metrics. I could create a custom table and put these tasks to it that table but again affects metrics and dashboards not looking at that table as well. So my best thought is to just create a physical Termination Catalog Item with workflow that creates a task/sctask, but don't display in the Service Portal and then push these Inbounds to the catalog item, which then I believe will create a Request & Request Item (hoping it does, wondering if it won't create the parent Request).
Do you have another idea?
-Wesley
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-21-2018 10:31 PM
I think the catalog item is the way to go, since in time you can encourage the HR dept to use the catalog itself.
You will need to use the CartJS API from the Inbound Action, if you're familiar with scripting.
This is the kind of script you will need on your Inbound Action:
var terminationSC = 'SYS_ID OF YOUR CATALOG ITEM';
var cart = new sn_sc.CartJS();
var item =
{
'sysparm_id': terminationSC,
'sysparm_quantity': '1',
};
cart.addToCart(item);
cart.setRequestedFor("94c26ab34f7d130050e5b63ca310c768");
//set the submitOrder output to a variable so we can get the request sys_id
var requestDetails = cart.checkoutCart();
var request = requestDetails.request_id;
//now lets lookup the RITM that was created and add the email subject and body to the additional comments, so you know what to do with it
var gr = new GlideRecord('sc_req_item');
gr.addQuery('request',request);
gr.query();
while(gr.next())
{
gr.comments = email.subject + '\n\n' + email.body_text.replace(/\n\n/g,"\n");
gr.update();
}
I did some brief testing on this - please note that I was always getting a null exception upon the ordering of the item, which seems to stop the GlideRecord lookup. However, the Request and Requested Item were being ordered successfully.