- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-04-2023 10:58 AM
How to auto populate current user's name phone number and email in a catalog item through client script and Script include.
Scenario: there are 3 variables in a catalog item: requested_for, phone_number and email.
client script: onLoad
function onLoad() {
//Type appropriate comment here, and begin script below
var ga = new GlideAjax('demoscript');
ga.addParam('sysParm_name', 'vishalj');
ga.addParam('sysParm_user', g_form.getValue('getUserID()'));
ga.getXML(getResponse);
function getResponse(response) {
var answer = response.responseXML.documentElement.getAttribute("answer");
var result = JSON.parse(answer);
g_form.setValue('requested_for', result.name);
g_form.setValue('email', result.email);
g_form.setValue('phone_number', result.phone);
}
}
Script include:
var demoscript = Class.create();
demoscript.prototype = Object.extendsObject(AbstractAjaxProcessor, {
vishalj: function(){
var gr = new GlideRecord('sys_user');
gr.addQuery('sys_id', this.getParameter('sysParm_user'));
gr.query();
if(gr.next()){
var obj = {};
obj.name = gr.name.toString();
obj.email = gr.email.toString();
obj.phone = gr.mobile_phone.toString();
return JSON.stringify(obj);
}
},
type: 'demoscript'
});
I used above script and methods but still not working. can anyone help in this?
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-04-2023 11:06 AM
Updated Script
function onLoad() {
//Type appropriate comment here, and begin script below
var ga = new GlideAjax('demoscript');
ga.addParam('sysparm_name', 'vishalj');
ga.getXML(getResponse);
function getResponse(response) {
var answer = response.responseXML.documentElement.getAttribute("answer");
var result = JSON.parse(answer);
g_form.setValue('requested_for', result.name);
g_form.setValue('email', result.email);
g_form.setValue('phone_number', result.phone);
}
}
Script include: client callable should be checked
var demoscript = Class.create();
demoscript.prototype = Object.extendsObject(AbstractAjaxProcessor, {
vishalj: function(){
var user = gs.getUserID();
var gr = new GlideRecord('sys_user');
gr.get(user);
var obj = {};
obj.name = gr.name.toString();
obj.email = gr.email.toString();
obj.phone = gr.mobile_phone.toString();
return JSON.stringify(obj);
},
type: 'demoscript'
});
If my answer solved your issue, please mark my answer as ✅ Correct & 👍Helpful based on the Impact.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-04-2023 11:04 AM
Hi Vishal,
Change the text for sysParm to be sysparm i.e. all in lower case
Also, did you try adding logs to see what is the result printed.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-04-2023 11:06 AM
Updated Script
function onLoad() {
//Type appropriate comment here, and begin script below
var ga = new GlideAjax('demoscript');
ga.addParam('sysparm_name', 'vishalj');
ga.getXML(getResponse);
function getResponse(response) {
var answer = response.responseXML.documentElement.getAttribute("answer");
var result = JSON.parse(answer);
g_form.setValue('requested_for', result.name);
g_form.setValue('email', result.email);
g_form.setValue('phone_number', result.phone);
}
}
Script include: client callable should be checked
var demoscript = Class.create();
demoscript.prototype = Object.extendsObject(AbstractAjaxProcessor, {
vishalj: function(){
var user = gs.getUserID();
var gr = new GlideRecord('sys_user');
gr.get(user);
var obj = {};
obj.name = gr.name.toString();
obj.email = gr.email.toString();
obj.phone = gr.mobile_phone.toString();
return JSON.stringify(obj);
},
type: 'demoscript'
});
If my answer solved your issue, please mark my answer as ✅ Correct & 👍Helpful based on the Impact.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-08-2024 06:14 AM - edited 05-08-2024 06:16 AM
We have an Auto-populate section while creating a field in catalog items, there you can select the Dependent Question as a User reference field and start with the Dot walk path. In the Dot walk path you will be able to see the fields from the user table, so that you can easily auto-populate the value without writing the script.