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-23-2025 06:10 AM
For one thing: why do you want to use inactive users on the portal? They aren't allowed to do anything on the instance, so why select them as user on a catalog item.
And next to that: the user query is there to do just that: hide any inactive users for any other users than admins. So anything you want to achieve for inactive users, you will have to disable that user query and ensure you create other logic for other parts of the system. You can't override a query business rule with other scripts/acls.
And finally: use the auto populate functionality on the catalog item instead of client scripts and script includes to create ajax calls. You don't need scripting to auto populate data on the catalog items anymore.
Please mark any helpful or correct solutions as such. That helps others find their solutions.
Mark
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-23-2025 07:18 AM
Hi Mark,
Thanks for your reply and providing me another shortcut. Anyways, my catalog item serves some purpose and our customer itself has asked for this particular requirement.
Serivce Request has to be raised on behalf of inactive user though we need inactive user's details to be populated over there.
Is there any possibility that you think we can do to have such requirement fulfilled?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-23-2025 11:44 PM
No, because a query BR is always evaluated before the list is queried and will hide the inactive users. You will need to update or inactivate the BR to get the requirement working.
Please mark any helpful or correct solutions as such. That helps others find their solutions.
Mark
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-29-2025 01:02 PM
You say the Catalog Item is "accessible to any user who can access SP portal". That sounds a little odd. So then, who can access the portal? ALL employees? If it was only for a limited number of people, you could:
- create a new Role
- assign the Role to an existing Group/Groups, if it makes sense, or create a new one to limit the number of users getting the Role
- modify the BR to include that new Role
That BR is tricky as it affects Reference and List fields EVERYWHERE. If you do this, Users with the new Role would see inactive User records everywhere. But if they are well trained and trusted by virtue of their position within the company, this can be done.
It makes sense, in general, that users should not see inactive User records so they do not select them by mistake, but there are definite use cases where those inactive User records should be selectable. And if it is for a limited number of users who may perform other tasks within the platform, their other specific Forms/Catalog Items could be modified to include a Reference Qualifier of "active=true" so that inactive records could not be selected in those particular cases.
Again, it all hinges on who has access to submit that request.