Get Phone Number from user record

sn624
Kilo Explorer

Hi Community,

I am trying to pull the requester's phone number from their file using the script below, however it's not working. Does anyone have any suggestions, as to what I am doing wrong here?

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

  if (isLoading) return;

  if (newValue == "") {

  g_form.setValue("phone", "");

  return;

  }

  //Call Script Include to get User phone number

  var ga = new GlideAjax("GetPhoneData");

  ga.addParam("sysparm_name", "getUserphone");

  ga.addParam("sysparm_user", g_form.getValue("new_phn_loc"));

  ga.getXML(updatephone);

}

function updateLocation(serverResponse) {

  //Process response from Script Include

  var answer = serverResponse.responseXML.documentElement.getAttribute("answer");

  g_form.setValue("phone", answer);

}

9 REPLIES 9

Anurag Tripathi
Mega Patron
Mega Patron

Hi Ciera,



Can you tell me that this client script is running onchange of which field, and also on which table.


And show the script include function also


-Anurag

Try this



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


  if (isLoading) return;


  if (newValue == "") {


  g_form.setValue("phone", "");


  return;


  }


  //Call Script Include to get User phone number


  var ga = new GlideAjax("GetPhoneData");


  ga.addParam("sysparm_name", "getUserphone");


  ga.addParam("sysparm_user", g_form.getValue("new_phn_loc"));


  ga.getXML(updatephone);


}


function updatephone(response) {


  //Process response from Script Include


  var answer = response.responseXML.documentElement.getAttribute("answer");


  g_form.setValue("phone", answer);


}


-Anurag

tltoulson
Kilo Sage

Hi Ciera,



On the line ga.getXML(updatephone) you are passing updatephone as the callback which does not exist.   Try passing updateLocation which is the function name you created to be used as the callback.


Tried this but still doesn't work



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


  if (isLoading) return;


  if (newValue == "") {


  g_form.setValue("phone", "");


  return;


  }


  //Call Script Include to get User phone number


  var ga = new GlideAjax("GetPhoneData");


  ga.addParam("sysparm_name", "getUserphone");


  ga.addParam("sysparm_user", g_form.getValue("new_phn_loc"));


  ga.getXML(updateLocation);


}



function updateLocation(serverResponse) {


  //Process response from Script Include


  var answer = serverResponse.responseXML.documentElement.getAttribute("answer");


  g_form.setValue("phone", answer);


}