Catalog Client Scripts: Get User Mobile Phone

rmechols
Kilo Contributor

In our request catalog we auto populate "On behalf of" and their "location." The Get User Location client Script looks like this:

 

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

if (newValue == '') {

return;

}

 

var obo = g_form.getValue('on_behalf_of').toString();

 

var user = new GlideRecord('sys_user');

user.addQuery('sys_id',obo);

user.query(callBack);

 

function callBack(user){

if(user.next()){

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

}

}

//Type appropriate comment here, and begin script below

 

}

 

It works like a charm. I am running into issues adding the User's Phone number. I modified the Get User Location Script but I can't get it to populate the phone onChange:

 

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

if (newValue == '') {

return;

}

 

var obo = g_form.getValue('on_behalf_of').toString();

 

var user = new GlideRecord('sys_user');

user.addQuery('sys_id',obo);

user.query(callBack);

 

function callBack(user){

if(user.next()){

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

}

}

//Type appropriate comment here, and begin script below

 

}

 

What am I missing? 

Thank you

 

1 ACCEPTED SOLUTION

Abhinay Erra
Giga Sage

In the catalog client script screenshot, the variable you selected is phone, it should be on behalf of instead. Change it to on behalf of and you are good to go

View solution in original post

15 REPLIES 15

Ok, I understand now. I changed the type to single line text and it still didn't work. 

Can you post a screenshot of your variable type and client script. I have tested this on my personal instance and it worked.

Update screenshot of type

find_real_file.png

function onChange(control, oldValue, newValue, isLoading) {
if (newValue == '') {
return;
}

var obo = g_form.getValue('on_behalf_of').toString();

var user = new GlideRecord('sys_user');
user.addQuery('sys_id',obo);
user.query(callBack);

function callBack(user){
if(user.next()){
g_form.setValue('phone',user.mobile_phone);
}
}
//Type appropriate comment here, and begin script below

}

 

find_real_file.png

 

 

 

 

Abhinay Erra
Giga Sage

In the catalog client script screenshot, the variable you selected is phone, it should be on behalf of instead. Change it to on behalf of and you are good to go

Abhinay Erra
Giga Sage

In the catalog client script screenshot, the variable you selected is phone, it should be on behalf of instead. Change it to on behalf of and you are good to go