Get multiple user attibutes in sys_user table by parsing email body text

Joe Taylor
Giga Guru

I'd like to parse an inbound email for a user employee number and use it to retrieve multiple other attributes in the record to populate a form.

 

My sys_user table has an attribute called "u_employee_number"

 

In the email body I'm user this variable pair

requestor:123456

 

In my inbound action script I'm trying 

var userid = new GlideRecord('sys_user');
userid.addQuery('u_employee_number',requestor);
userid.query();
if(userid.next()){
var id = userid.sys_id();

}

 

Then I want use the sys_id in my catalog item:

 

if(requestor!=undefined)
hddcart.setVariable(item,"requestor_name",id);

 

This isn't working.

 

Can you help?

1 ACCEPTED SOLUTION

Hi @Joe Taylor 

 

You can fetch multiple attributes using the same object:

 

 if (email.body.requestor != undefined){
    var userid = new GlideRecord('sys_user');
    userid.addQuery('u_employee_number', email.body.requestor);
    userid.query();
    if(userid.next()){
    var id = userid.getUniqueValue();
    hddcart.setVariable(item,"requestor_name",id);
    hddcart.setVariable(item,"variable1_name",userid.field_name.getValue());
    hddcart.setVariable(item,"variable2_name",userid.field_name.getValue());
    }
}
 
Example:
hddcart.setVariable(item,"variable_name",userid.name.getValue());  //name
hddcart.setVariable(item,"variable_name",userid.title.getValue());   //title
hddcart.setVariable(item,"variable_name",userid.department.getValue());   //department
 
Thanks!
 
Mark it as helpful and correct if it works ✔️👍

View solution in original post

5 REPLIES 5

Omkar Kumbhar
Mega Sage
Mega Sage

Hello @Joe Taylor ,

Directly the variable will not work in inbound action.

Please first retrive the email body by using the below syntax

 

var emailBody= email.body_text;

then try to get the employee number from the body

 

var requester= emailBody[1];

then gliderecord to sys_user table. Please debug it according.

 

Thank you,

Omkar

If I was able to help you with your case, please click the Thumb Icon and mark as Correct.