- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-30-2017 10:10 AM
I'm working on a request item to update a users phone number. The workflow will push this change to AD. I'm looking for the most simple way to display what the current value of the logged in user's phone number is on the form. It should not be editable.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-30-2017 10:50 AM
Hi David,
Let's say you have a field called 'phonenumber' on your form.
Add the following catalog client script (assuming that you want it to show in the catalog item when the user opens a request):
function onLoad() {
//Type appropriate comment here, and begin script below
var usrid = g_user.userID; //this will get the current user's phone
var user = new GlideRecord('sys_user');
user.addQuery('sys_id', usrid); //this will find it in the users table
user.query();
if(user.next()) {
g_form.setValue('phonenumber', user.phone); //this will set the phone number from the user profile in the phone field
g_form.setReadOnly('phonenumber', true); //readonly
}
}
If your needs are different or something is not clear, let me know.
Harel
Please mark as correct or helpful based on impact.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-30-2017 10:50 AM
Hi David,
Let's say you have a field called 'phonenumber' on your form.
Add the following catalog client script (assuming that you want it to show in the catalog item when the user opens a request):
function onLoad() {
//Type appropriate comment here, and begin script below
var usrid = g_user.userID; //this will get the current user's phone
var user = new GlideRecord('sys_user');
user.addQuery('sys_id', usrid); //this will find it in the users table
user.query();
if(user.next()) {
g_form.setValue('phonenumber', user.phone); //this will set the phone number from the user profile in the phone field
g_form.setReadOnly('phonenumber', true); //readonly
}
}
If your needs are different or something is not clear, let me know.
Harel
Please mark as correct or helpful based on impact.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-30-2017 01:57 PM
I used your script to in a different request for that is doing basically the same thing except it is a request to update the manager information. I'm trying to use the following to set the value just as you did above, but I'm getting the value of the sys_id returned. Which is expected due to it being a reference field. However, getDisplayValue doesn't work either, and I've read the articles on getDisplayBox() as well can nothing I do is making it work correctly. Any suggestions.
g_form.setValue('old_manager', user.manager);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-30-2017 02:12 PM
You are getting the sys_id because you are trying to populate a string field. Change the type of the string field to reference and point it to User [sys_user].
Either that, or try to change it to:
g_form.setValue('old_manager', user.manager.name);
harel
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-30-2017 02:23 PM
You were 100% right about it being a string. Changing it to a reference worked like a champ. Thanks so much!!