Populating active and inactive user details to any user who can access SP Portal
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-23-2025 05:40 AM - edited 01-23-2025 05:43 AM
Hi Everyone,
I'm stuck in a requirement where I have to populate user details like name, phone, email, manager name, etc. in a catalog item which is accessible to any user who can access SP portal.
Right now, I have made a script include and a client script and has some single line text variables in catalog item in which details get populated when I enter the email of the user.
Having admin role, when I enter email address, it populates details of both active and inactive users. When impersonating any non-admin user, it works only for active users and some times even not, inactive user details doesn't populate.
There is a out of the box business rule "user query" which is restricting this. But I dont want to touch the business rule as it is global and can affect other things as well.
Script include that I'm using
var GetUserDetails = Class.create();
GetUserDetails.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getUserInfo: function() {
var email = this.getParameter('sysparm_user_email');
var userGr = new GlideRecord('sys_user');
userGr.setWorkflow(false);
userGr.addQuery('email', email);
userGr.query();
if (userGr.next()) {
if (userGr.active == false) {
return JSON.stringify({ error: 'This user has left the organization' });
}
var assets = this.getUserAssets(userGr.sys_id);
return JSON.stringify({
sys_id: userGr.getValue('sys_id'),
name: userGr.getValue('name'),
location: userGr.getDisplayValue('location'),
manager: userGr.getDisplayValue('manager'),
assets: assets,
email: userGr.getValue('email') // Include email in the response
});
}
return JSON.stringify({ error: 'There is no user present in the system with the mentioned email address' });
},
});
Client Script that I'm using on single line text variable "enter_the_email_address"
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
// Regular expression to validate email format
var emailPattern = /^[a-zA-Z0-9._%+-]+@gmail\.com$/;
if (!emailPattern.test(newValue)) {
g_form.showFieldMsg('enter_the_email_address', 'This is not a valid email address', 'error');
clearFields();
return;
} else {
g_form.hideFieldMsg('enter_the_email_address');
}
// Call a function to get user details based on the new email
GetUserDetails(newValue);
}
function GetUserDetails(email) {
if (email) {
var ga = new GlideAjax('GetUserDetails');
ga.addParam('sysparm_name', 'getUserInfo');
ga.addParam('sysparm_user_email', email);
ga.getXMLAnswer(function(response) {
if (response) {
var user = JSON.parse(response);
if (user.error) {
g_form.showFieldMsg('enter_the_email_address', user.error, 'error');
clearFields();
} else {
g_form.setValue('name_of_the_user', user.name || '');
g_form.setValue('leaver_location1', user.location || '');
g_form.setValue('Phone1', user.phone || '');
g_form.setValue('manager_s_name1', user.manager || '');
g_form.setValue('asset_list', user.assets || '');
}
}
// else {
// clearFields();
// }
});
}
else {
clearFields();
}
}
function clearFields() {
g_form.setValue('name_of_the_user', '');
g_form.setValue('leaver_location1', '');
g_form.setValue('Phone1', '');
g_form.setValue('manager_s_name1', '');
g_form.setValue('asset_list', '');
}
What should I do so that any one filling my catalog item can see the user details wether the user is active or inactive?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-30-2025 01:12 AM
Adding to that: as soon as the role is granted to users and the BR is adjusted, those users will also be able to select inactive users on assigning tickets (or any other reference field to the user table), so the reference qualifiers need to be changed.
Please mark any helpful or correct solutions as such. That helps others find their solutions.
Mark