Want to hide a variable if the logged in user has a role using Catalog Client script

jonathangilbert
Kilo Sage

Hi All

I have been looking on the forum and I cant see a solution for what I am trying to achieve on a catalog item.

I am trying to hide a variable on the Portal Form if the user has a role, but the suggestions I have tried and tried to tweak do not work.

 

Here is my script:-

 

  function onLoad() {
    if (g_user.hasRoleExactly('New_starter_vip_colleague',true))
        return;
        g_form.setDisplay("colleagues_name",false);
    
    
}
 
So if the logged in user has the role "New_starter_vip_colleague", then hide the "colleagues_name" variable
 
Many Thanks all
1 ACCEPTED SOLUTION

Ankur Bawiskar
Tera Patron
Tera Patron

@jonathangilbert 

do this

function onLoad() {

	if (g_user.hasRoleExactly('New_starter_vip_colleague'))
		g_form.setDisplay("colleagues_name",false);

}

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

View solution in original post

4 REPLIES 4

Vishal Birajdar
Giga Sage

Hi @jonathangilbert 

 

You should not use "return" in second line as next line code will not run.

 

Can you try this..!!

 

  function onLoad() {

    if (g_user.hasRoleExactly('New_starter_vip_colleague')) {
//you need to make mandatory false if they are mandatory
g_form.setMandatory("colleagues_name",false);
        g_form.setVisible("colleagues_name",false);

    }

}

 

Vishal Birajdar
ServiceNow Developer

I know one thing, and that is that I know nothing.
- Socrates

Ankur Bawiskar
Tera Patron
Tera Patron

@jonathangilbert 

do this

function onLoad() {

	if (g_user.hasRoleExactly('New_starter_vip_colleague'))
		g_form.setDisplay("colleagues_name",false);

}

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

jonathangilbert
Kilo Sage

Thank you once again Ankur 🙂

@jonathangilbert 

Glad to help.

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader