Inbound Email Action is setting the 'Requested for' field as Guest when though the user exists

sreenivaskumar
Giga Contributor

Hi,

I had created an Inbound Email Action to create a request every time we receive an email with a certain keyword from one particular email address. I had later created a user account with this email address. Now this inbound email action is working but the 'requested for' field comes up as guest instead of the name of the account i created with that email address. But it correctly shows the account name in the Email logs under User ID column

 

This is the code i am using to get the requested for field info

cart.requested_for = myUserObject.getRecord().getValue('sys_id');

 

I am not sure if this is wrong

1 ACCEPTED SOLUTION

Jim Coyne
Kilo Patron

Try:

cart.requested_for = sys_email.user_id;

"sys_email" is a GlideRecord of the email record the Inbound Action is responding to.

View solution in original post

7 REPLIES 7

Brad Tilton
ServiceNow Employee
ServiceNow Employee

I think this would probably result in the same thing, but I would use:
cart.requested_for = gs.getUser().getID();

If that doesn't work it would be helpful to see all the code.

sreenivaskumar
Giga Contributor

Hi Brad,

 

Apologies for the late response. No this code as well dint work.

 

Here is the entire code i am using

createRequest();
function createRequest() {
var cart = new Cart();
var myUserObject = gs.getUser().getUserByID(email.body.reqfor.toString());

var item = cart.addItem('sys id of the request item');

cart.setVariable(item, 'request_short_description', email.subject);
cart.setVariable(item, 'request_description', email.subject);
cart.setVariable(item, 'request', 'request name');
cart.setVariable(item, 'comments', email.body_text);

cart.requested_for = myUserObject.getRecord().getValue('sys_id');
cart.update();
var rc = cart.placeOrder();

 

var req = new GlideRecord ('sc_request'); 
req.get(rc.sys_id); 
req.requested_for = myUserObject.getRecord().getValue('sys_id');

req.opened_by = myUserObject.getRecord().getValue('sys_id');
req.update();

var onegr = new GlideRecord('sc_req_item');
onegr.addQuery('request',rc.sys_id);
onegr.query();
if(onegr.next())
{
onegr.opened_by = myUserObject.getRecord().getValue('sys_id');
onegr.update();
  }

}

Are you looking to set the requested for to be the user account with the email address that the email came from, or a value from the body of the email?

Hi Brad,

 

Apologies once again for the late response. Its for the first one, requested for to be the user account with the email address that the email came from