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

Elijah Aromola
Mega Sage

Have you checked the phone number you're getting in msg_phone vs the field value? The query looks good but I think that the value you're providing doesn't match the format of the field.

 

Please mark this as correct/helpful if it resolved your issue!

well...yes, the phone numbers match.  In the log I get The Phone number is 1112223333 and when I filter the user list for business phone 11122223333 I get a result.  Now, I do notice that the field is not a string type...it's phone number type.  This could be the problem...but I don't know how to get around that....

 

when i run my script below i get the correct user record.

set the caller_id to the sys_id of the user.

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();