Default Phone Variable Value

akunk23
Kilo Contributor

Hello

Right now, when a user opens a service request, the form auto populates the phone number with the logged in user. I want the phone variable to be based off of the "requested for" variable. How would I go about doing this? Here is the script in the default value for the phone variable.

find_real_file.png

I'm not sure I'm wanting to actually get the userID? I may be wrong though. Thank you

13 REPLIES 13

sumanteegala
Kilo Expert

you can write an onchange client script on variable name requested for



if(newValue!='')


{


var reqfrm = g_form.getReference('requested_for', phne);



function phne(reqfrm(


{


g_form.setValue('phone',reqfrm.phone);


{


Madhu27
Tera Expert

Please try this



    var ga = new GlideAjax('getUserInfo');


      ga.addParam('sysparm_name','userInfo');


      ga.addParam('sysparm_user_name',g_form.getValue('requesting_for'));


      ga.getXML(parseResponse);


     


      //Return results


      function parseResponse(response) {


              var result = response.responseXML.getElementsByTagName("result");


             


              var userPhone = result[0].getAttribute("userPhone");


             


             


              //Load Form with new phone number



      }


akunk23
Kilo Contributor

In the Default Value field?


BALAJI40
Mega Sage

Use this line of code in your default value section:


javascript:gs.getUser().getRecord().getDisplayValue("phone"); // This set the value of login user by onLoad



if you want populate the user phone number, on change of User you need to write onChange catalog client script.


akunk23
Kilo Contributor

Balaji,



I'm trying to write the onChange catalog client script. Will I need to delete the default value script from the actual variable also?