autopopulate field
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-29-2023 02:06 AM
I added to the incident table a field called call back (u_call_back) of string type.
I need to autopopulate this field with the caller's mobile phone as default value.
What is the problem with the code?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-29-2023 03:03 AM
Hi @Shir Sharvit ,
Create onChange Client Script as below will populate the Call back base on the Caller field:
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
if (newValue != oldValue) {
var caller = g_form.getReference('caller_id', popCallerInfo);
}
function popCallerInfo(caller) {
var callBackVal = caller.u_call_back;
if (callBackVal != '') {
g_form.setValue('u_call_back', callBackVal);
}
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-29-2023 03:53 AM
It does not work
I made the following code:
function onChange() {
var callerId = g_form.getValue('caller_id');
if (callerId) {
// Fetch the caller's record
var caller = new GlideRecord('sys_user');
if (caller.get(callerId)) {
// Get the mobile phone from the caller's record
var mobilePhone = caller.mobile_phone;
// Set the u_call_back field in the incident form
g_form.setValue('u_call_back', mobilePhone);
}
}
}
But it doesn't work for me in SOW - service operation workspace

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-30-2023 01:24 AM
@Shir Sharvit , if this is onChange - Client script on the Caller field, you don't have to specify g_form.getValue('caller_id'), it is in the newValue.
And should avoid using GlideRecord in Client side script.
I just change the code to take mobile_phone from user record:
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
if (newValue != oldValue) {
var caller = g_form.getReference('caller_id', popCallerInfo);
}
function popCallerInfo(caller) {
var mobileVal = caller.mobile_phone;
if (mobileVal != '') {
g_form.setValue('u_call_back', mobileVal);
}
}
}
Please try again, and test it in Incident form first because workspace sometimes will acts differently.