Company field not populating from user record to new incident

dlively
Giga Expert

When we open a new incident, the phone number is auto-populating based on the Caller as it should.   I need to figure out why the Company field is not auto-populating.

I see from the dictionary that the phone number field is coming from the User[sys_user] table,  the Type is phone number, column label is business phone, and name is phone.   There is no Choice List Specification, no Dependent field, no Calculated Value and no Default Value.

However, in the dictionary for the Company field, the Table is User [sys_user], the Type is Reference, column label is company and name is company.   The Reference Specification is Company with no qualifying condition.   There is also an Access Control called sys_user.company.   I have attached screen prints of the Access Controls.

Can someone point me in the direction of how to get the Company field to auto-populate on a new Incident record?

Thank you,

Donna Lively

8 REPLIES 8

Bharath40
Giga Guru

Hi Donna,



You can get this done by using the client script. Below is the client script for company. You can use it for other fields too.


function onChange(control, oldValue, newValue, isLoading) {


  if (isLoading)


  return;



  if (newValue == '') {


  g_form.setValue('company', '');


  return;


  }



  if (!g_form.hasField('company'))


  return;



  var caller = g_form.getReference('caller_id', setLocation);





  function setLocation(caller) {


  if (caller)


  g_form.setValue('location', caller.company);


  }


}



This will be on Incident table where you want the fields to be populated. please let me know if you have other questions.


Mike Allen
Mega Sage

There is a business rule called Company Projection that should set it on insert and update.   Most people will have a client script that says something like:



onChange of user field



function onChange(control, oldValue, newValue, isLoading) {


    var caller = g_form.getReference('caller_id', changeCompany);


}


function changeCompany(caller) { //reference is passed into callback as first arguments


  g_form.setValue('company', caller.company);


}


Mike,


Thank you so much for your prompt response. I am very new to ServiceNow. Can you please give me detailed directions for applying this client script? Do I just paste your script over the one that is currently there?



Below is the script that currently lies at (BP) Set Location to User client script.



function onChange(control, oldValue, newValue, isLoading) {


if (isLoading)


return;



if (newValue == '') {


g_form.setValue('location', '');


return;


}



if (!g_form.getControl('location'))


return;



var caller = g_form.getReference('caller_id', setlocation);


}



function setlocation(caller) {


if (caller)


g_form.setValue('location', caller.location);


}



Donna Lively


(409)880-7151




Hi Donna,



you can copy paste this script in your client script, this is for company field as you requested for.


function onChange(control, oldValue, newValue, isLoading) {


  if (isLoading)


  return;


  if (newValue == '') {


  g_form.setValue('company', '');


  return;


  }


  if (!g_form.hasField('company'))


  return;


  var caller = g_form.getReference('caller_id', setLocation);


  function setLocation(caller) {


  if (caller)


  g_form.setValue('location', caller.company);


  }


}



Please let me know if you have any other questions.



Thanks,


Bharath