# Perspective issue after making the necessary changes in start up script

**URL:** <https://forum.inductiveautomation.com/t/perspective-issue-after-making-the-necessary-changes-in-start-up-script/76859>\
**Category:** Ignition\
**Tags:** ignition81, perspective\
**Created:** [July 25, 2023, 12:41pm UTC](https://forum.inductiveautomation.com/t/perspective-issue-after-making-the-necessary-changes-in-start-up-script/76859 "2023-07-25T12:41:09Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![Surya\_Chandra\_Mohan](https://avatars.discourse-cdn.com/v4/letter/s/a9adbd/32.png) [@Surya\_Chandra\_Mohan](https://forum.inductiveautomation.com/u/Surya_Chandra_Mohan)\
**Post date:** [July 25, 2023, 12:41pm UTC](https://forum.inductiveautomation.com/t/perspective-issue-after-making-the-necessary-changes-in-start-up-script/76859/1 "2023-07-25T12:41:10Z")

</div>

Hello,  
I am currently trying to enable a button when administrator users role are logged in from perspective and disable a button when only regular users are logged in.

I have attached the snapshot of the code!

Can you please help me out with this issue?  
 ![2023-07-25](https://us1.discourse-cdn.com/inductiveautomation/original/3X/2/2/22a8b3f8d4d87665f69ae15d2a0990f3149ae1f9.png)

---

<div class="post-metadata">

**Author:** ![Kevin.Herron](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kevin.herron/32/7259_2.png) [@Kevin.Herron](https://forum.inductiveautomation.com/u/Kevin.Herron)\
**Post date:** [July 25, 2023, 12:52pm UTC](https://forum.inductiveautomation.com/t/perspective-issue-after-making-the-necessary-changes-in-start-up-script/76859/2 "2023-07-25T12:52:55Z")

</div>

You haven't explained what your issue is.

I'll tell you one thing, though: `system.user.getRoles` returns a _List_ of roles, so comparing it directly to "Admin" won't work.

---

<div class="post-metadata">

**Author:** ![Surya\_Chandra\_Mohan](https://avatars.discourse-cdn.com/v4/letter/s/a9adbd/32.png) [@Surya\_Chandra\_Mohan](https://forum.inductiveautomation.com/u/Surya_Chandra_Mohan)\
**Post date:** [July 25, 2023, 12:57pm UTC](https://forum.inductiveautomation.com/t/perspective-issue-after-making-the-necessary-changes-in-start-up-script/76859/3 "2023-07-25T12:57:45Z")

</div>

Apologies,

I have created two roles with one being "Administrator" and the other being "User"  
And there's a spelling error - it is Administrator and not Admin

The problem lies when the button is not enabled or disabled for the respective conditions when I try to login with Admin or User credentials

---

<div class="post-metadata">

**Author:** ![CalebM](https://avatars.discourse-cdn.com/v4/letter/c/71c47a/32.png) [@CalebM](https://forum.inductiveautomation.com/u/CalebM)\
**Post date:** [July 25, 2023, 1:06pm UTC](https://forum.inductiveautomation.com/t/perspective-issue-after-making-the-necessary-changes-in-start-up-script/76859/4 "2023-07-25T13:06:42Z")

</div>

Where does this script live? Is it a custom method on the root container?

---

<div class="post-metadata">

**Author:** ![Surya\_Chandra\_Mohan](https://avatars.discourse-cdn.com/v4/letter/s/a9adbd/32.png) [@Surya\_Chandra\_Mohan](https://forum.inductiveautomation.com/u/Surya_Chandra_Mohan)\
**Post date:** [July 25, 2023, 1:08pm UTC](https://forum.inductiveautomation.com/t/perspective-issue-after-making-the-necessary-changes-in-start-up-script/76859/5 "2023-07-25T13:08:37Z")

</div>

The script is written in the root container on startup

---

<div class="post-metadata">

**Author:** ![CalebM](https://avatars.discourse-cdn.com/v4/letter/c/71c47a/32.png) [@CalebM](https://forum.inductiveautomation.com/u/CalebM)\
**Post date:** [July 25, 2023, 1:14pm UTC](https://forum.inductiveautomation.com/t/perspective-issue-after-making-the-necessary-changes-in-start-up-script/76859/6 "2023-07-25T13:14:29Z")

</div>

I think the issue is what Kevin had mentioned. You are trying to compare a list to a string. You could check if 'Administrator' is in the list of roles `if "Admin" in role:`. A simpler approach may be to use an expression binding directly on the enabled property of the button. `indexOf('Administrator',{session.props.auth.user.roles})>-1` might work correctly in the expression binding.

---

<div class="post-metadata">

**Author:** ![CalebM](https://avatars.discourse-cdn.com/v4/letter/c/71c47a/32.png) [@CalebM](https://forum.inductiveautomation.com/u/CalebM)\
**Post date:** [July 25, 2023, 1:18pm UTC](https://forum.inductiveautomation.com/t/perspective-issue-after-making-the-necessary-changes-in-start-up-script/76859/7 "2023-07-25T13:18:22Z")

</div>

The expression binding should be: `indexOf({session.props.auth.user.roles}, 'Administrator')>-1`. I had switched the order of the parameters.

---

<div class="post-metadata">

**Author:** ![Felipe\_CRM](https://avatars.discourse-cdn.com/v4/letter/f/dfb087/32.png) [@Felipe\_CRM](https://forum.inductiveautomation.com/u/Felipe_CRM)\
**Post date:** [July 25, 2023, 1:28pm UTC](https://forum.inductiveautomation.com/t/perspective-issue-after-making-the-necessary-changes-in-start-up-script/76859/8 "2023-07-25T13:28:42Z")

</div>

In expressions, `hasRole(role, username, usersource)` will also work (the second and third argument are required for Perspective):

> [@Perspective: Error using hasRole(...) with only 1 argument](https://forum.inductiveautomation.com/t/perspective-error-using-hasrole-with-only-1-argument/26628/13):
>
> Why are you forcing the double quotes? The example only has double quotes to display that the value is a String.

You'll need to get username and user source from the session props, here's a more specific example. I just included the other one because of the nice screenshot:

> [@Perspective: Error using hasRole(...) with only 1 argument](https://forum.inductiveautomation.com/t/perspective-error-using-hasrole-with-only-1-argument/26628/15):
>
> I try to avoid double quotes if I can help it, but your original ‘shoulda worked’ works for me: hasRole('Operator', {session.props.auth.user.userName}, {session.props.auth.idp})

---

<div class="post-metadata">

**Author:** ![nminchin](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/nminchin/32/6911_2.png) [@nminchin](https://forum.inductiveautomation.com/u/nminchin)\
**Post date:** [July 25, 2023, 11:23pm UTC](https://forum.inductiveautomation.com/t/perspective-issue-after-making-the-necessary-changes-in-start-up-script/76859/9 "2023-07-25T23:23:24Z")

</div>

To make it clear, you should _ **never** _ use the startup script to disable graphic components directly (not that you can). You should always use a binding on the component, or, in rare circumstances, a script from another graphical component in the same view.

Consider the situation where you need to add other conditions to the enable button as well. If you use a startup script, you're screwed (so too are you using another component script without thinking, hence why I said that would be rare)

---

<div class="post-metadata">

**Author:** ![Surya\_Chandra\_Mohan](https://avatars.discourse-cdn.com/v4/letter/s/a9adbd/32.png) [@Surya\_Chandra\_Mohan](https://forum.inductiveautomation.com/u/Surya_Chandra_Mohan)\
**Post date:** [July 26, 2023, 4:13am UTC](https://forum.inductiveautomation.com/t/perspective-issue-after-making-the-necessary-changes-in-start-up-script/76859/10 "2023-07-26T04:13:38Z")

</div>

Thank you caleb  
It is working now
