Set Reference field
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-24-2023 10:27 PM
Hi everyone,
I have one requirement like on the user table we have 'department' reference field and same type of reference field i have added its name 'u_department' in my custom table now I want to set from user source table value of department field to value on department field in my custom table.
I have written below code:
could you please help me in where i have done mistake.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-24-2023 10:43 PM
@rmaroti Do you have User field reference on your custom table?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-25-2023 02:32 AM
yes, I have 'u_employee' field its playing same role like caller field played in incident table.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-25-2023 03:05 AM
@rmaroti Create an onChange client script on the u_employee field on your custom table. As soon as the u_employee field changes, the value of department field defined on custom table will set to the department set on the employee record.
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
var act = g_form.getValue('u_active');
if(act == 'true'||act==true){
var employee = g_form.getReference('u_employee', setDepartment); /
}
}
function setDepartment(employee){
g_form.setValue('u_department',employee.department);
}
Hope this helps.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-24-2023 10:57 PM - edited 11-24-2023 11:00 PM
Hi @rmaroti
Try the following code. Don't forget to replace your user field name in custom table.
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
var act = g_form.getValue('u_active');
if(act == 'true' || act == '1' || act == true){
var emp = g_form.getReference('u_user', setDept); //Replace u_user with your field name
}
}
function setDept(emp){
g_form.setValue('u_department',emp.department);
}
Please mark my answer helpful and accept as a solution if it helped 👍✅
Anvesh