title: Undefined when trying to change a field. ServiceNow
body: <p>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.</p>
  
  <p>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.)</p>
  
  <p>That works fine. But when it changes User Affected the Office Location should populate the location but it only populates 'Undefined'</p>
  
  <p>But when i myself change the User Affected field it works fine.</p>
  
  <p>is there a difference between my script changing something and me changing something? here is the script.</p>
  
  <pre><code>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); }
  </code></pre>
  
  <p>Here is the script to populate User Affecting from caller</p>
  
  <pre><code>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); }
  </code></pre>