Creating SC Task from Inbound Email but can't populate 'Requested For' with Email Sender

Wesley Breshear
Tera Expert

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

1 ACCEPTED SOLUTION

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.

View solution in original post

7 REPLIES 7

Akash4
Kilo Sage
Kilo Sage

Hi Wesley,

 

I verified using a normal onLoad client script to see if this requested for gets populated.

Here is a sample code: 

function onLoad() {
	// if browser supports angular and is new UI, hide checklist related list
	if (g_scratchpad.browserSupported && g_scratchpad.isNewUI)
		g_form.hideRelatedList("REL:8f576281c3100200e280dccdf3d3aed8");
	g_form.setValue('assigned_to','46d44a23a9fe19810012d100cca80666');
	g_form.setValue('requested_for','46d44a23a9fe19810012d100cca80666');

}

find_real_file.png

 

All I can see is, as I gave the same sys id for both assigned to and requested for, only Assigned to field is getting populated and not the requested for.

 

Reason:

Assigned to is coming from core 'task' table while the Requested for is coming from 'sc_request' table.

We can populate the fields that are outside the parent child relation but not inside the relationship. Hope this helps your query.

 

Remedy: As a remedy plan you can use anyother table or create a custom table for the sake. Thank you

 

Regards,

Akash

Regards, Akash
If my response proves useful, please mark it "Accept as Solution" and "Helpful". This action benefits both the community and me.

Ah, your right. When I try to save the record manually the name disappears.  Looks like I will need to create Request/Request Item for this to work.

Thanks!

-Wesley

Jamie Imms
Kilo Expert

Hi Wesley,

If you have a dot walked field against your record, then you shouldn't be able to save values against it if you have to linkage to the dot walked parent record. If you try to save, it should be blank. So essentially, you won't be able to write anything to the field itself, should the Task record not have a Requested Item assigned to it.

I would confirm that the 'Requested For' field is actually the Request's field by right clicking on it and going to the Dictionary. The table should be sc_request.

 

The reason why your script won't work is because you are attempting to update a value on a separate table. You will need to call that record directly in a GlideRecord and update it, like so:

 

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 gr = new GlideRecord('sc_request');
gr.get(current.request_item.request);
gr.requested_for = email.origemail;
gr.update();

current.assignment_group = 'b60f0c4f0f344700b855f08ce1050e3a'; // Software Development Tools Support
current.priority = 4;
current.setAbortAction(true);
current.insert();

 

This should work, assuming that your email.origemail variable is a valid sys_id of a user.

Hi Jamieimms,
 
Yea, pretty sure the Glide Record will not work because I am not creating a Request Item from the Inbound action, hence, no sc_request exist to query.  So looks like I will need to go back and create a Catalog Item for 'Terminations', which then I can create from the inbound and then use your script or I think that I could dot.walk then.
 
Thanks,
-Wesley