- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-30-2019 08:56 AM
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;
}
Solved! Go to Solution.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-30-2019 09:04 AM
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();

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-30-2019 09:00 AM
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!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-30-2019 09:06 AM
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....
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-30-2019 09:15 AM
when i run my script below i get the correct user record.
set the caller_id to the sys_id of the user.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-30-2019 09:04 AM
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();