Got it! If you want to print the Caller: Manager, Location, Department, Email on the form (for example, into some fields or a message), and use g_form.getReference without console.log, here are some ways to display them:
Option 1: Show values inside existing fields on the form
You can create read-only fields on the form (e.g., Manager Name, Location Name, Department Name, Email) and set their values via g_form.setValue().
Assuming you created 4 string fields on the form, for example:
u_caller_manager (string)
u_caller_location (string)
u_caller_department (string)
u_caller_email (string)
You can write this Client Script (e.g., onChange on caller_id):
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || !newValue) {
// Clear fields if no caller
g_form.setValue('u_caller_manager', '');
g_form.setValue('u_caller_location', '');
g_form.setValue('u_caller_department', '');
g_form.setValue('u_caller_email', '');
return;
}
g_form.getReference('caller_id', function(caller) {
if (!caller) {
g_form.setValue('u_caller_manager', 'Not found');
g_form.setValue('u_caller_location', 'Not found');
g_form.setValue('u_caller_department', 'Not found');
g_form.setValue('u_caller_email', 'Not found');
return;
}
var managerName = caller.manager ? caller.manager.display_value : 'None';
var locationName = caller.location ? caller.location.display_value : 'None';
var departmentName = caller.department ? caller.department.display_value : 'None';
var email = caller.email || 'None';
g_form.setValue('u_caller_manager', managerName);
g_form.setValue('u_caller_location', locationName);
g_form.setValue('u_caller_department', departmentName);
g_form.setValue('u_caller_email', email);
});
}
Option 2: Use g_form.showFieldMsg() to show messages near the caller field
If you want to display the information as a message on the form (like a toast or error/info message near the field), you can use g_form.showFieldMsg().
Example:
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || !newValue) {
g_form.hideFieldMsg('caller_id', true);
return;
}
g_form.getReference('caller_id', function(caller) {
if (!caller) {
g_form.showFieldMsg('caller_id', 'Caller not found.', 'error');
return;
}
var managerName = caller.manager ? caller.manager.display_value : 'None';
var locationName = caller.location ? caller.location.display_value : 'None';
var departmentName = caller.department ? caller.department.display_value : 'None';
var email = caller.email || 'None';
var msg = 'Manager: ' + managerName + '<br>' +
'Location: ' + locationName + '<br>' +
'Department: ' + departmentName + '<br>' +
'Email: ' + email;
g_form.showFieldMsg('caller_id', msg, 'info', false);
});
}
This will show an info message directly under the caller_id field, nicely formatted with line breaks.
If you want it to be persistent till manually removed, set last param to true.
Option 3: Use a UI Macro or UI Page to show data (Advanced)
This option is more involved, so Option 1 or 2 are simpler for your case.
Summary:
- Create string fields to hold the values if you want to show on the form in fields (Option 1).
- Use
g_form.setValue() in the callback of getReference.
- Or use
g_form.showFieldMsg() to display info near the caller field (Option 2).
- Avoid
console.log() if you want visible info on the UI.
If you want me to write a full onLoad Client Script example or a UI Policy + Client Script solution, just ask!