How I hide/disbale the Activity Button on the list/form for one user?

Sandro Ulisses
Tera Contributor

Hi guys,

I'm needing to improve a function to hide/disable the activity stream button on the form or list.

How I can do this, for one user when some conditions was satisfied.

I create a role u_activity_stream_no and I attributed to a group of users don't access the functionality.

I wrote a code below:

Script Client: OnLoad

 

function onLoad() {

   addLoadEvent(hideListStreamButton);

   function hideListStreamButton() {

      if (g_user.hasrole("u_activity_stream_no")) {

         if ($$('.list_stream_button')[0]) {

             $$('.list_stream_button')[0].hide();

         }

        if ($$('.form_stream_button')[0]) {

           $$('.form_stream_button')[0].hide();

        }
    }

   }
}

 

But don't get the result desired.

 
2 REPLIES 2

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

Using DOM manipulation is not recommended

I hope you have set Isolate Script = False for your onLoad client script

update your script as this

function onLoad() {

	addLoadEvent(hideListStreamButton);

	function hideListStreamButton() {

		if (g_user.hasRoleExactly("u_activity_stream_no")) {
			gel('form_stream').style.display = 'none'; // hide
		}
		else{
			gel('form_stream').style.display = ''; // show
		}

	}
}

Regards
Ankur

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

Hello @Ankur Bawiskar,

 

Thank you so much for your response. I'm facing the same issue, however when I implement this client script, the form stops working while creation of a new record. All the reference fields do not get loaded.

 

My guess was that this line 

gel('form_stream').style.display = ''

is the problem, since we are passing empty value. But that isn't the case either. Your help is highly appreciated