- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-03-2024 10:47 AM
I have added three variables which are one is "Name [reference of sys_user], another one is Email [string type], and the last variable is Mobile [string type]" for catalog items
if I select the user in the Name field then the details will be populated in the email and mobile fields automatically.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-03-2024 10:54 AM
Hi @Prasad Kumar ,
onChange client script on your reference field:
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading) {
return;
}
if(newValue === ''){
g_form.setValue('<mobile number variable name>','');
g_form.setValue('<email id variable name','');
}
var ga = new GlideAjax('GetUserDetails');
ga.addParam('sysparm_name','getDetails');
ga.addParam('sysparm_user_id',newValue);
ga.getXML(CallBack);
function CallBack(response) {
var answer = response.responseXML.documentElement.getAttribute("answer");
answer = answer.evalJSON(); //Transform the JSON string to an object
g_form.setValue('<manager variable name>',answer.manager);
g_form.setValue('<mobile number variable name>',answer.number);
g_form.setValue('<email id variable name',answer.email);
}
}
Script Include and select client callable option:
Name: GetUserDetails
Client callable: true
Script:
var GetUserDetails = Class.create();
GetUserDetails.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getDetails: function(){
var obj = {};
var usr= new GlideRecord('sys_user');
usr.get(this.getParameter('sysparm_user_id'));
obj.manager = usr.getValue('manager');
obj.email = usr.getValue('email');
obj.number=usr.getValue('mobile_phone');
var json = new JSON();
var data = json.encode(obj);//JSON formatted string
return data;
},
type: 'GetUserDetails'
});
If I could help you with your Query then, please hit the Thumb Icon and mark it as Correct !!
Thanks & Regards,
Sumanth Meda
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-03-2024 10:54 AM
Hi @Prasad Kumar ,
onChange client script on your reference field:
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading) {
return;
}
if(newValue === ''){
g_form.setValue('<mobile number variable name>','');
g_form.setValue('<email id variable name','');
}
var ga = new GlideAjax('GetUserDetails');
ga.addParam('sysparm_name','getDetails');
ga.addParam('sysparm_user_id',newValue);
ga.getXML(CallBack);
function CallBack(response) {
var answer = response.responseXML.documentElement.getAttribute("answer");
answer = answer.evalJSON(); //Transform the JSON string to an object
g_form.setValue('<manager variable name>',answer.manager);
g_form.setValue('<mobile number variable name>',answer.number);
g_form.setValue('<email id variable name',answer.email);
}
}
Script Include and select client callable option:
Name: GetUserDetails
Client callable: true
Script:
var GetUserDetails = Class.create();
GetUserDetails.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getDetails: function(){
var obj = {};
var usr= new GlideRecord('sys_user');
usr.get(this.getParameter('sysparm_user_id'));
obj.manager = usr.getValue('manager');
obj.email = usr.getValue('email');
obj.number=usr.getValue('mobile_phone');
var json = new JSON();
var data = json.encode(obj);//JSON formatted string
return data;
},
type: 'GetUserDetails'
});
If I could help you with your Query then, please hit the Thumb Icon and mark it as Correct !!
Thanks & Regards,
Sumanth Meda
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-03-2024 11:59 AM
Hey @Prasad Kumar,
You can use the 'Auto-populate' functionality.
Within your catalog variable, configure the 'auto-populate' tab something like the below:
Cheers