Auto fill user's phone on Incident form

brown9394
Tera Expert

Hello Experts,

I have a requirement to auto fill user's phone number from caller's profile on the Incident form, how can I populate caller's 'Business Phone' number from the user's profile automatically when the Caller is selected?

Screen Shot 2017-01-14 at 1.57.03 PM.png

1 ACCEPTED SOLUTION

Hi James,



As previously mentioned, the simplest approach is to model your solution after the base platform incident client script '(BP) Set Location to User'. This script runs client-side 'onChange' for field 'Caller'. It essentially gets the referenced user's location and copies it to the location field on the form. This use-case is pretty simple since both the source and target fields are a reference type and do not require any formatting.



It is possible to use the same approach for a phone number, but depending on your requirements for localization/normalization, the answer is a bit more complicated..



If you plan on using the base platform field "sys_user.phone) as your source, this column is of type 'Phone Number' (ph_phone). This can easily be mapped to a string type field, however you will not have the basic formatting capabilities on the incident form. It is technically possible to create a column with the legacy ph_phone type to enable one-to-one mapping with basic formatting, but I would recommend reaching out to ServiceNow for guidance as this field type is not readily available to customers.



Here's a sample of what an incident client script could look like as an 'onChange' type for field 'Caller' assuming your source field is named 'phone' and target field is 'u_contact_number'.



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


  if (isLoading) {


          return;


  }



  if (newValue == '') {


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


          return;


  }



  if (!g_form.getControl('u_contact_number')) {


          return;


  }



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


}




function setContactNumber(caller) {


  if (caller) {


          g_form.setValue('u_contact_number', caller.phone);


  }


}



If you plan on using a source or target field that is an E.164 Phone Number, I would recommend reviewing the docs and community posts regarding usage as the E.164 field type can be a bit difficult to setup and utilize in certain cases.



Thanks,


Aric


View solution in original post

11 REPLIES 11

IamGroot
Tera Contributor

Hi James



You can go to Incident form > Configure List Layout


find_real_file.png


You can directly add the caller's phone from caller reference field, you won't have to create a new field for this purpose.



Thanks


BR


Rajiv


Thanks Rajiv,



however, how can I re-lable the field from 'business phone' to 'Contact Number' without changing it globally?


Hi James,


You can try dictionary override.



BR


Rajiv


Yes, I tried that. For some reason I keep getting an error trying to create a new label. for the field. Even though there is only one that's showing.



Screen Shot 2017-01-14 at 3.02.41 PM.png


Screen Shot 2017-01-14 at 3.03.12 PM.png