auto populate values based on another field value

Dinesh Kumar C
Tera Contributor

I have a field which is referenced to "sys_user" table . If i select a value from user table then value of some other fields populate automatically . Below are the fields

find_real_file.png

Do i need to Business rule or client script to archive this ? How

1 ACCEPTED SOLUTION

Harsh Vardhan
Giga Patron

Hi Dinesh,



Please try with script below.



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


    var caller = g_form.getReference('caller_id', doAlert); // doAlert is our callback function


}


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


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


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


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


}



Please change the variable name that you have exactly on your catalog form.


View solution in original post

10 REPLIES 10

prasadh
Giga Contributor

Hi Dinesh,



You can achieve this using scripting. You can use dot walking also.



Dot Walking: Dot-Walking - ServiceNow Wiki



Thanks,


Prasad


shruti_tyagi
ServiceNow Employee
ServiceNow Employee

Hi Dinesh,



I would recommend to use OnChange client script to auto populate these values on the basis of requested for field.


http://wiki.servicenow.com/index.php?title=Client_Scripts#onChange.28.29_Scripts


http://wiki.servicenow.com/index.php?title=GlideForm_(g_form)#setValue



Take example of OOB client script '(BP) Set Location to User' that sets location on the basis of caller:


https://your_instance.service-now.com/sys_script_client.do?sys_id=5e524025c0a80166004d1761e85e2058



Thanks


Shruti


If the reply was informational, please like, mark as helpful or mark as correct!


Harsh Vardhan
Giga Patron

Hi Dinesh,



Please try with script below.



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


    var caller = g_form.getReference('caller_id', doAlert); // doAlert is our callback function


}


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


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


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


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


}



Please change the variable name that you have exactly on your catalog form.


Hi Harsh,

I need to know why variable caller got created?