The CreatorCon Call for Content is officially open! Get started here.

Hide a Widget based on the account of the logged in user

jabaya
Mega Guru

Hello gurus,

I need help with a Service Portal requirement. where i have a widget with a filter which i cloned and set filter of the cloned widget a little different, the challenged i have is to show / hide the widgets based on the logged is user.

the original widget will be the default one.

while the cloned widget will only show for the users of a certain account  ( example. account = xyz ).

i have tried to do a server script in the widget directly. ( tho im not knowledgeable enough to complete the script. -hence why i need help 🙂 ).

Attached is what I'm working on , any suggestions will be appreciated ❤️ Thankyou in advance 🙂


 

// Create a new GlideRecord object for the user table
var grUser = new GlideRecord('sys_user');

// Get the current logged-in user ID
var loggedInUser = gs.getUserID();

// Query the user record for the logged-in user
if (grUser.get(loggedInUser)) {
    // Check if the user account is 'urban utilities'
    if (grUser.u_account == 'XYZ') {
        gs.info('User account is XYZ');
        // Perform actions for the specific user account
	(-------------NOT SURE------------ what to add here to SHOW the widget)
    } else {
        gs.info('User account is not urban utilities');
        // Perform actions for other user accounts or handle accordingly
	(-------------NOT SURE------------ what to add here to HIDE the widget)
    }
} else {
    gs.info('Unable to find the logged-in user record');
}

 

 

6 REPLIES 6

Hi @jabaya ,

 

as company is a reference field u need to use sys_id of "Urban Utilities" 

 

 

 

	if (companyValue == '<add_sys_id_of_urben_utilities>') {
							data.isUrbanUtilities = true;
						}

 

 

 

If my response helped you, please click on "Accept as solution" and mark it as helpful.
Thanks

Suraj!

i did try this, however it did not work. (it did work in the sense of  logs the isUrbanUtilities = true now) however the widget still stays hidded. also another thing that i am concern of is that this will be hardcoded and will not be a best practice......