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 07:50 AM
Hi Kevin,
Assuming you're trying to populate your location variable with the location of the user in your caller_id variable, use this in your catalog client script.
function onChange(control, oldValue, newValue, isLoading) {
if (newValue != '') {
var caller = g_form.getReference('caller_id', setName);
}
function setName(caller) {
g_form.setValue('locationvariablename', caller.location);
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-18-2016 08:40 AM
I apologize for any confusion I caused in this post. I am not so much worried about the location as I am if the user exists in the sys_user table. If they exist there and are selected, populate the email (email) and Business phone number (phone) from the sys_user table.
I suppose I need to create an onChange() catalog client script which will be run when the "name" field changes and will pull the email and phone records for that user. If there is no user existing in the sys-user table, it will need to be created. Once the name is selected, then, those two values can be pulled from the database.
Thank you for your assistance with this.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-18-2016 10:48 AM
b-rad, I tried implementing this code into my catalog client script and found it did not produce any results. I could have tried to bundle too much together in one Catalog Client Script (CCS). My code is listed below:
function onChange(control, oldValue, newValue, isLoading) {
if (newValue != '') {
var callerName = g_form.getReference('name', setName);
var callerEmail = g_form.getReference('email', setEmail);
var callerPhone = g_form.getReference('phone', setPhone);
var callerMobPhone = g_form.getReference('mobile_phone', setMobPhone);
}
}
function setName(callerName) {
g_form.setValue('name', callerName.name);
}
function setEmail(callerEmail) {
if (callerEmail != '') {
return;
} else {
g_form.setValue('email', callerEmail.email);
}
}
function setPhone(callerPhone) {
if (callerPhone != '') {
return;
} else {
g_form.setValue('phone', callerPhone.phone);
}
}
function setMobPhone(callerMobPhone) {
if (callerMobPhone != '') {
return;
} else {
g_form.setValue('mobile_phone', setMobPhone);
}
}
Now that I look at the CCS, I am wondering if I should break this out into separate CCSs for each field that needs to be updated. Currently, I the code listed above is the script section for a CCS with the following settings:
Name: Update Caller Name
Applies To: A Variable Set
Type: onChange
Variable Set: AU_PR
Variable Name: name
Applies on: Catalog Tasks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-19-2016 04:48 AM
b-rad, I separated out the CCS into separate client scripts and the name field seems to not pull the data I am needing it to pull. These are the Catalog Client Scripts I created, which, none of them are working. I have tried multiple variations, nothing seems to help this work at all:
Name: Update Requester Name
Applies To: A Variable Set
Variable Set: AU_PR
Variable Name: name
Script:
function onChange(control, oldValue, newValue, isLoading) {
if (newValue != '') {
return;
}
}
function setName(callerName) {
g_form.setValue('name', callerName.name);
}
Name: Update Requester E-mail
Applies To: A Variable Set
Variable Set: AU_PR
Variable Name: email
Script:
function onChange(control, oldValue, newValue, isLoading) {
if (callerEmail != '') {
var callerEmail = g_form.getReference('email', setEmail(callerEmail));
}
}
function setEmail(callerEmail) {
g_form.setValue('email', callerEmail.email);
}
Name: Update Requester Name
Applies To: A Variable Set
Variable Set: AU_PR
Variable Name: name
Script:
function onChange(control, oldValue, newValue, isLoading) {
if (newValue != '') {
var callerPhone = g_form.getReference('phone', setPhone());
}
}
function setPhone(callerPhone) {
g_form.setValue('phone', callerPhone.phone);
}
Any help would be appreciated. I think I need to dot walk to the table I need to access the data from.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-19-2016 01:23 PM
I spoke to nabilenayet about this and he suggested using the out of the box Catalog Client Script, Populate Manager and Name, which is very similar to what I am wanting to perform. As he said, this triggers off a `department` field and then writes `manager` and `email`. I need to trigger off of the Name field, and write to a `phone` and `email` field. Thus, the code needs to be modified and added to my Catalog Client Script. Working on that now. Will post my results.