Populate a Catalog Task field in Record Producer with Requested Name's phone number
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-18-2016 06:47 AM
I created a Record Producer and have a Variable Set on it. The Variable Set includes the following items:
Requester Name
Requester Email
Phone Number
I would like to add a script for the Default Value on the Variable that will pull the phone number from the Requester Name, which is a reference to the "sys_user" table, when it is populated. How would I go about pulling the data from the database if the user record is there. If Requester Name is selected from the User look up or created via a new User, would like to populate the Requester Email & Phone Number fields.
I saw a post where b-rad used a default value to set the phone value from the user record. in the following manner:
javascript: var userPhone; var user = new GlideRecord('sys_user'); if (user.get(gs.getUserID())) {userPhone = user.phone}; userPhone;
I have not delved into Script Includes yet. However, that is in my near future plans.
Thank you
Message was edited by: Kevin Eldridge
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-21-2016 05:41 AM
Thank you for the assistance everyone. With the help of pheedbaq and nabilenayet I was able to get this working with the help of this Catalog Client Script, which only applies to Catalog Item view and my variable set:
function onChange(control, oldValue, newValue, isLoading) {
// If name is blank or form is loading, exit
if (isLoading || !newValue)
return;
// Change the name field (Which is a reference field),
// pull the whole record, and then try to populate
// our other variables
g_form.getReference('name', updateUser);
}
function updateUser(gr) {
g_form.clearMessages();
// If there is an email address in the user object that has been passed to us, use it
if (gr.email) {
g_form.setValue('email', gr.email);
}
// If there is an Business phone in the user object that has been passed to us, use it
if (gr.phone) {
g_form.setValue('phone', gr.phone);
}
}
Still need to add the functionality to clear out the additional fields if the gliderecord object does not have data for them. Otherwise, values could be left behind if the person filling out the form changes the user selection, and the new user's record is not as complete as the previous one.