- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-23-2023 05:02 AM
I am new to SNOW. I am trying to auto populate the description field of an incident form with location of the logged in user using getReference method in onload client script and I cannot get it right.
function onLoad() {
//Type appropriate comment here, and begin script below
var user=g_form.getReference('caller_id',callBack);
function callBack(user){
g_form.setValue('description',user.email);
}
}
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-23-2023 05:37 AM - edited ‎01-23-2023 05:39 AM
Hi @Madhan007 Use below Scripts to fulfill your requirement.
Step 1] Create use below script in onLoad Client script.
function onLoad() {
//Type appropriate comment here, and begin script below
var caller = g_form.getValue('caller_id');
var ga = new GlideAjax('global.AG_based_on_caller'); //here global.AG_based_on_caller Script Include Name
ga.addParam('sysparm_name', 'getRecord'); // here getRecord function in Script Include
ga.addParam('sysparm_user', caller);
ga.getXML(callback);
function callback(response) {
var answer = response.responseXML.documentElement.getAttribute("answer");
g_form.setValue('description', answer);
}
}
Step 2] Create one Client Callable Script Inlcude.
var AG_based_on_caller = Class.create();
AG_based_on_caller.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getRecord: function() {
var user_sys = this.getParameter('sysparm_user');
gs.info("user_sys-" + user_sys);
var user = new GlideRecord("sys_user");
user.addQuery('sys_id', user_sys);
user.query();
if (user.next()) {
var loc = user.location; //Location field on User table.
return loc;
}
},
type: 'AG_based_on_caller'
});
If I could help you with your Query then, please hit the Thumb Icon and mark as Correct !!
Thank You

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-23-2023 05:38 AM
Hi @Madhan007 ,
To auto populate the logged in user details:
Add in default value to that variables : javascript:gs.getUserID()//name of logged in user.
javascript:gs.getUser().getRecord().getValue('phone_number');//phone number
javascript:gs.getUser().getRecord().getValue('location');//location
AS shown in Screen shot:
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-23-2023 05:27 AM
Hi @Madhan007
Just wanted to confirm where is your location field. On Users[sys_user] table?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-23-2023 05:37 AM - edited ‎01-23-2023 05:39 AM
Hi @Madhan007 Use below Scripts to fulfill your requirement.
Step 1] Create use below script in onLoad Client script.
function onLoad() {
//Type appropriate comment here, and begin script below
var caller = g_form.getValue('caller_id');
var ga = new GlideAjax('global.AG_based_on_caller'); //here global.AG_based_on_caller Script Include Name
ga.addParam('sysparm_name', 'getRecord'); // here getRecord function in Script Include
ga.addParam('sysparm_user', caller);
ga.getXML(callback);
function callback(response) {
var answer = response.responseXML.documentElement.getAttribute("answer");
g_form.setValue('description', answer);
}
}
Step 2] Create one Client Callable Script Inlcude.
var AG_based_on_caller = Class.create();
AG_based_on_caller.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getRecord: function() {
var user_sys = this.getParameter('sysparm_user');
gs.info("user_sys-" + user_sys);
var user = new GlideRecord("sys_user");
user.addQuery('sys_id', user_sys);
user.query();
if (user.next()) {
var loc = user.location; //Location field on User table.
return loc;
}
},
type: 'AG_based_on_caller'
});
If I could help you with your Query then, please hit the Thumb Icon and mark as Correct !!
Thank You

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-23-2023 05:38 AM
Hi @Madhan007 ,
To auto populate the logged in user details:
Add in default value to that variables : javascript:gs.getUserID()//name of logged in user.
javascript:gs.getUser().getRecord().getValue('phone_number');//phone number
javascript:gs.getUser().getRecord().getValue('location');//location
AS shown in Screen shot: