Reputation: 11
I am working with three fields : caller, User Affected, and Office Location. Just building this small script to expand on. newb here if you cant tell. Our org has just started working in service now. fresh out of the admin training.
When Caller changes it populates the User Affected field with the username as well. (we have many instances of someone putting in incidents for other people.)
That works fine. But when it changes User Affected the Office Location should populate the location but it only populates 'Undefined'
But when i myself change the User Affected field it works fine.
is there a difference between my script changing something and me changing something? here is the script.
function onChange(control, oldValue, newValue, isLoading) { if (isLoading) return;
if (newValue == '') { g_form.setValue('u_office_location', ''); return; }
if (!g_form.getControl('u_office_location')) return;
var u_user_affected = g_form.getReference('u_user_affected', setLocation); }
function setLocation(u_user_affected) { if (u_user_affected) g_form.setValue('u_office_location', u_user_affected.u_office_location); }
Here is the script to populate User Affecting from caller
function onChange(control, oldValue, newValue, isLoading) { if (isLoading) return;
if (newValue == '') { g_form.setValue('u_user_affected', ''); return; }
if (!g_form.getControl('u_user_affected')) return;
var caller = g_form.getReference('caller_id', setLocation); }
function setLocation(caller) { if (caller) g_form.setValue('u_user_affected', caller.name); }
Upvotes: 1
Views: 1745
Reputation: 11
I was populating the field with caller.name which is just text. i was not populating the reference
Here is the fix for the script that populated User Affected from Caller.
function onChange(control, oldValue, newValue, isLoading) {
var id = g_form.getValue('caller_id');//replace 'u_first_field' with the name of your reference field.
if (g_form.getValue('u_user_affected') == ""){
g_form.setValue('u_user_affected', id);
}
}
Upvotes: 0