Auto fill phone number from User table

pratibha4
Kilo Contributor

I have a form in the service catalog for ordering an item. The first field in the form is a reference field to sys_user. This field is auto-filled with the name of the person ordering the item.

And the second field is the phone number of the user.I want to fetch this phone number from the user table, so I have made this a Reference field of the user table. And in the default value, I am using : javascript:gs.getMobileNumber()

But it is not working. Do I need to use client script for this?

Any help would be appreciated. Thanks!

1 ACCEPTED SOLUTION

Hello Pratibha:


You can create the user object, you can get any objects related to the user, like phone number, location etc;


var myUserObject = gs.getUser()
myUserObject.getMobileNumber() will return the mobile phone number of the user.


Hope this helps



P.S Mark it correct or helpful.


Regards


Danny


View solution in original post

5 REPLIES 5

Ravi Prasad1
Tera Guru

yes you have to write onchange client script on caller variable.



Write the below lines:



var user=g_form.getReference('user_name_variable');


g_form.setValue('phone_number',user.phone_number);




fd.JPG



Let me know if you need any help !!!


Hi Ravi,



Thanks for the reply!



Actually, it is a mandatory field, so, Shouldn't I write an onLoad Client script?


If you write above onchange script then it will execute on setting of the Caller ID so it will set the phone number on load of the form itself.



Write this script and let me know if you need any help.


Hello Pratibha:


You can create the user object, you can get any objects related to the user, like phone number, location etc;


var myUserObject = gs.getUser()
myUserObject.getMobileNumber() will return the mobile phone number of the user.


Hope this helps



P.S Mark it correct or helpful.


Regards


Danny