Get email of Requested for user
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-29-2024 02:15 AM
Hi All,
I have to variables in catalog item:
One is 'Requested for' which is a List collector to choose more than one user
Then I see also user id, email and so on
But there are some security restrictions for some users and they don't see user id, email
So I've created the second variable "users info" which is a Multi Line Text and also I've created Client Script to push user id, email of 'Requested for" to this second variable.
But currently I see only user ID, what should I change/add to see also email?
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var user_id = g_form.getValue("requested_for_info");
var userIDArray = user_id.split(',');
var userinfo = '';
function processUserInfo(i) {
var ga = new GlideAjax('getCatalogItemsInfo');
ga.addParam('sysparm_name', 'getUserInfo');
ga.addParam('sysparm_userID', userIDArray[i]);
ga.getXMLAnswer(function(response) {
userinfo += response;
g_form.setValue("users_info", userinfo);
});
}
for (var i = 0; i < userIDArray.length; i++) {
processUserInfo(i);
}
}
Thanks in advance for help!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-29-2024 02:28 AM
Hello @Kasia5 ,
this depends on the Function "getUnserInfo" in your Script-Include "getCatalogsItemsInfo".
If the script include is using GlideRecord to fetch user data, then you could return the additional fields.
However if it is using GlideRecordSecure, which is recommended for client callable script includes, the access controls will not allow to return this sensitive information.
I recommend that you don't try to get sensitive information. There must be some reason why the access controls are in place.
Malte
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-29-2024 02:37 AM
Another suggestion to get the information via ServiceNow api instead of the custom script include could be the following code. However the security constraints are still in place.
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var userGr = new GlideRecord('sys_user');
userGr.addQuery('sys_id', 'IN', g_form.getValue("requested_for_info"));
userGr.query(function(userGr) {
var userInfos = [];
while (userGr.next()) {
var userName = userGr.name;
var userId = userGr.user_name;
var email = userGr.email;
userInfos.push(userName + ', ' + userId + ', ' + email);
}
g_form.setValue("users_info", userInfos.join('\n'));
});
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-29-2024 02:58 AM
Please share getCatalogItemsInfo script
Regards,
Piyush Sain
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-29-2024 04:50 AM
Hi @Kasia5 ,
You can try the below SI and Client script,
var getUserEmail = Class.create();
getUserEmail.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getEmail: function() {
var table = this.getParameter('sysparm_query_table');
var sysid = this.getParameter('sysparm_id');
gs.info('line number 8 ' + sysid);
var grEmails = new GlideRecord(table);
grEmails.addEncodedQuery(sysid);
grEmails.query();
var arr = [];
while(grEmails.next()) {
gs.info('line number 14 inside while');
arr.push(grEmails.name.toString() + ': ' + grEmails.email);
}
gs.info('line number 15', arr.toString());
return arr.toString();
},
type: 'getUserEmail'
});
client script:
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var liststr = g_form.getValue('requested_for').toString();
var ga = new GlideAjax('getUserEmail');
ga.addParam('sysparm_name', 'getEmail');
ga.addParam('sysparm_query_table', 'sys_user');
ga.addParam('sysparm_id', "sys_idIN" + liststr + ",");
ga.getXML(getResponse);
}
function getResponse(response) {
var ans = response.responseXML.documentElement.getAttribute('answer');
alert('answer ' + ans);
g_form.setValue('users_info', ans.replaceAll(",","\n"));
g_form.setReadOnly('users_info', true);
}
Please mark this comment as Correct Answer/Helpful if it helped you.
Regards,
Swathi Sarang