- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-21-2020 05:20 AM
Unable to retrieve the value which is being passed from server script
Server script:-
data.name = '';
data.email = '';
// get current user email
var uemail;
var usr = new GlideRecord('sys_user');
usr.addQuery('sys_id', gs.getUserID());
usr.query();
if(usr.next())
{
data.email = usr.email;
}
client script:-
var temp = c.data.email;
alert(JSON.stringify(c.data.email));
Alert returns empty { }
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-21-2020 05:46 AM
Assumption - you are using Service Portal. If this is standard lists/forms, please clarify. The approach is totally different.
Note: Always assume (because it's true) that fields are objects. If you want the value, use getValue() or getDisplayValue().
Server script:
data.email = '';
var usr = new GlideRecord('sys_user');
if (usr.get(gs.getUserID()) {
data.email = usr.getValue('email');
if (data.email == '') {
gs.error('This user has no email');
}
} else {
gs.error('Unable to read current user record');
}
Client script:
console.log('Email=' + c.data.email);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-21-2020 05:27 AM
Try usr.getDisplayValue('email').
If not in a scoped application try using usr.getValue('email').
Or using the string method on it: usr.email.toString();
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-21-2020 05:37 AM
i was able to get the value in console.log for the server script
but in client controller its showing empty value

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-21-2020 05:46 AM
Assumption - you are using Service Portal. If this is standard lists/forms, please clarify. The approach is totally different.
Note: Always assume (because it's true) that fields are objects. If you want the value, use getValue() or getDisplayValue().
Server script:
data.email = '';
var usr = new GlideRecord('sys_user');
if (usr.get(gs.getUserID()) {
data.email = usr.getValue('email');
if (data.email == '') {
gs.error('This user has no email');
}
} else {
gs.error('Unable to read current user record');
}
Client script:
console.log('Email=' + c.data.email);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-21-2020 05:35 AM
Hi,
Try this,
Script Include:
getDetails: function() {
var user_sys_id = this.getParameter('sysparm_userid');
var user = new GlideRecord('sys_user');
var result = {
email:""
};
if (user.get(user_sys_id)) {
result.email = user.email;
}
return JSON.stringify(result);
},
OnLoad client script:
var ga=new GlideAjax('scriptIncludeName');
ga.addParam('sysparm_name','getDetails');
ga.addParam('sysparm_userid',gs.getUserID());
ga.getXML(responseParse);
function responseParse(response){
var answer= response.responseXML.documentElement.getAttribute("answer");
var res = JSON.parse(answer);
g_form.setValue('field_name',res.email);
}
Regards,
Sagar Pagar