query sys_user for phone number

Daniel Shock
Kilo Sage

Good morning!

We have support group phone numbers that send emails with audio files attached when a caller leaves a voicemail.  The subject of the email contains the phone number of the caller.  I would like to be able to search the business phone field on the sys_user table for a match and then set the caller of the incident to that user. 

The first part of my code is working... I'm getting a number.  But the second part, the query is returning nothing to the log...

anyone have any ideas?

It should be pretty easy...but I'm stuck.  here is what I have so far:

 

var msg_phone = email.subject.slice(email.subject.indexOf('(')+1, email.body_text.indexOf(')'));

gs.log('Phone Number is '+ msg_phone);

var usr = new GlideRecord('sys_user');
 usr.addQuery('phone',msg_phone);
 usr.query();
 if (usr.next())
{
gs.log('User id is '+ usr);
current.caller_id = usr.user_name;	
	
}
1 ACCEPTED SOLUTION

ggg
Giga Guru

var usr = new GlideRecord('sys_user');
usr.addQuery('phone','111-222-3333');
usr.query();
if (usr.next())
    {
    gs.info('User name is '+ usr.name);
    
}

caller_id needs the sys_id of the user record:

current.caller_id = usr.getUniqueValue();
 

View solution in original post

5 REPLIES 5

ha that was it.... fixed it all.  thank you!!