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-18-2016 06:49 AM
You can use my method to pull from the logged in user. If you need to use data from the user object in the reference variable, your best bet is probably a g_form.getReference() call.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-18-2016 06:55 AM
Thank you b-rad for your quick response. Can you help me to put this in place if the attributes of the variables are as follows, how would I go about doing this?
Question: Requester Name
Name: name
Type: Reference to User [sys_user]
Question: Requester Email
Name: email
Type: Reference to User [sys_user]
Question: Phone Number
Name: userPhone
Type: Single Line Text
I am trying to write a script to go into the default value field and this is what I have thus far.
function onChange(control, oldValue, newValue, isLoading){var caller = g_form.getReference('caller_id', setName);} function setName(caller){ if (caller != '') {alert('User name is blank')} else { caller = user.name); };} caller;
Can you validate if this is good or would this be best to use a Script Include. If it is best to use a Script Include, how would I go about using that for this instance?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-18-2016 07:18 AM
Hi Kevin,
You wouldn't use the default value or script include for this, you'd want to use an onChange catalog client script that runs off your reference variable.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-18-2016 07:44 AM
I apologize for lack of knowledge on this and have been trying to get this to work properly. However, it is not working for me. I am the process of creating a catalog client script that will do what I need it to in order to process this request.
I created the following catalog client script:
function onChange(control, oldValue, newValue, isLoading) {
newValue = caller;
var caller = g_form.getReference('caller_id', setName);
}
function setName(caller) {
if (caller != '') {
alert('User name is blank');
} else {
caller = user.name;
}
}
Does this look correct to you for setting the name and then, I could create a similar catalog client script to validate when the User is populated to update the email and phone variables
I moved this to the Developer Community and out of ITOM: General