# IF name is true OR if role is true (contained the role)

**URL:** <https://forums.knack.com/t/if-name-is-true-or-if-role-is-true-contained-the-role/12640>\
**Category:** Ask Developers\
**Created:** [June 6, 2022, 2:45pm UTC](https://forums.knack.com/t/if-name-is-true-or-if-role-is-true-contained-the-role/12640 "2022-06-06T14:45:17Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![MichaelG](https://sea2.discourse-cdn.com/flex020/user_avatar/forums.knack.com/michaelg/32/758_2.png) [@MichaelG](https://forums.knack.com/u/MichaelG)\
**Post date:** [June 6, 2022, 2:45pm UTC](https://forums.knack.com/t/if-name-is-true-or-if-role-is-true-contained-the-role/12640/1 "2022-06-06T14:45:17Z")

</div>

Before you post here, first search for an existing topic to Hi guys, I am trying to add another condition in my JS code but it does not work.

this works:

/_Show edit IDEA if Responsible of Idea"_/  
$(document).on(‘knack-view-render.view\_265’, function(event, view, data) {  
$(’#view\_265 div.kn-details-link’).hide();  
var LoggedInUser = (Knack.getUserAttributes().name);  
var Responsible = $(’#view\_265 div.kn-detail.field\_271 \> div.kn-detail-body’).text();  
if(LoggedInUser === Responsible) {  
$(’#view\_265 div.kn-details-link’).show();  
};  
});see if this question has already been asked and answered. If not, create a new topic!

Be concise, but don’t forget to provide context for your question, explaining what you need help with using specific examples. Screenshots and links encouraged.

This does not work:

/\*Show edit button IF Responsible of the Idea OR Coordinator (contains the role) \*/

$(document).on(‘knack-view-render.view\_265’, function(event, view, data) {  
$(’#view\_265 div.kn-details-link’).hide();  
var LoggedInUser = (Knack.getUserAttributes().name);  
var Responsible = $(’#view\_265 div.kn-detail.field\_271 \> div.kn-detail-body’).text();  
if(LoggedInUser === Responsible) { $(’#view\_265 div.kn-details-link’).show(); }  
else if( (Knack.getUserAttributes().roles(‘Coordinator’)) ) { $(’#view\_265 div.kn-details-link’).show(); } ;  
});

tks for any help

---

<div class="post-metadata">

**Author:** ![Sunny\_Singla](https://sea2.discourse-cdn.com/flex020/user_avatar/forums.knack.com/sunny_singla/32/1007_2.png) [@Sunny\_Singla](https://forums.knack.com/u/Sunny_Singla)\
**Post date:** [June 6, 2022, 5:34pm UTC](https://forums.knack.com/t/if-name-is-true-or-if-role-is-true-contained-the-role/12640/2 "2022-06-06T17:34:09Z")

</div>

Hello Michael,

Knack.getUserAttributes().roles gives you roles in for of object\_xyz, not as a role name.

try below  
if(Knack.getUserAttributes().roles.indexOf(‘object\_xyz’)\>0)

Change xyz to original object nme.

Regards,  
Sunny Singla  
[ssingla1985@gmail.com](mailto:ssingla1985@gmail.com)

> **[Database consultant – Software database consultant](http://sandt-consultancyservices.com)**
>
> Knack Database consultant

---

<div class="post-metadata">

**Author:** ![MichaelG](https://sea2.discourse-cdn.com/flex020/user_avatar/forums.knack.com/michaelg/32/758_2.png) [@MichaelG](https://forums.knack.com/u/MichaelG)\
**Post date:** [June 7, 2022, 8:29am UTC](https://forums.knack.com/t/if-name-is-true-or-if-role-is-true-contained-the-role/12640/3 "2022-06-07T08:29:40Z")

</div>

Perfect Sunny! Works at the first try.  
tks you!  
Much user-cases I have for that.

---

<div class="post-metadata">

**Author:** ![MichaelG](https://sea2.discourse-cdn.com/flex020/user_avatar/forums.knack.com/michaelg/32/758_2.png) [@MichaelG](https://forums.knack.com/u/MichaelG)\
**Post date:** [June 7, 2022, 8:47am UTC](https://forums.knack.com/t/if-name-is-true-or-if-role-is-true-contained-the-role/12640/4 "2022-06-07T08:47:50Z")

</div>

I spoke to soon. Doesn’t work yet.

if(Knack.getUserAttributes().roles.indexOf(‘object\_xyz’)\>0)

Here I don’t see where the object roles are compared to the role (Coordinator) I am looking for.

---

<div class="post-metadata">

**Author:** ![Sunny\_Singla](https://sea2.discourse-cdn.com/flex020/user_avatar/forums.knack.com/sunny_singla/32/1007_2.png) [@Sunny\_Singla](https://forums.knack.com/u/Sunny_Singla)\
**Post date:** [June 7, 2022, 9:04am UTC](https://forums.knack.com/t/if-name-is-true-or-if-role-is-true-contained-the-role/12640/5 "2022-06-07T09:04:30Z")

</div>

> [@MichaelG](#):
>
> looking

Check that object id in builder when you click on that role it show that role id in url.

 ![image](https://us1.discourse-cdn.com/flex020/uploads/knack/original/2X/e/ee3318659371e85c1802631a72cf0c902feafe69.png)  
Like this it’s object\_26

also you can check in console by running Knack.getUserAttributes().roles it give you all roles connected to that user.

Thanks  
Sunny Singla

---

<div class="post-metadata">

**Author:** ![MichaelG](https://sea2.discourse-cdn.com/flex020/user_avatar/forums.knack.com/michaelg/32/758_2.png) [@MichaelG](https://forums.knack.com/u/MichaelG)\
**Post date:** [June 7, 2022, 9:17am UTC](https://forums.knack.com/t/if-name-is-true-or-if-role-is-true-contained-the-role/12640/6 "2022-06-07T09:17:04Z")

</div>

I am looking for the roles of the Logedin User.  
So if I run Knack.getUserAttributes().roles it gives me all roles of the logedin user.

now I need to check if one of those roles is equal to Coordinator. how to do that?

---

<div class="post-metadata">

**Author:** ![MichaelG](https://sea2.discourse-cdn.com/flex020/user_avatar/forums.knack.com/michaelg/32/758_2.png) [@MichaelG](https://forums.knack.com/u/MichaelG)\
**Post date:** [June 7, 2022, 9:18am UTC](https://forums.knack.com/t/if-name-is-true-or-if-role-is-true-contained-the-role/12640/7 "2022-06-07T09:18:40Z")

</div>

else if( (Knack.getUserAttributes().roles(‘Coordinator’)) ) { $(’#view\_265 div.kn-details-link’).show(); } ;

here I need to compare Knack.getUserAttributes().roles with Coordinator. 🤔

---

<div class="post-metadata">

**Author:** ![Sunny\_Singla](https://sea2.discourse-cdn.com/flex020/user_avatar/forums.knack.com/sunny_singla/32/1007_2.png) [@Sunny\_Singla](https://forums.knack.com/u/Sunny_Singla)\
**Post date:** [June 7, 2022, 9:19am UTC](https://forums.knack.com/t/if-name-is-true-or-if-role-is-true-contained-the-role/12640/8 "2022-06-07T09:19:31Z")

</div>

That i already show you go to builder and click on that object (Coordinator) you will see at top(URL) for object id  
as i show in screenshot

---

<div class="post-metadata">

**Author:** ![MichaelG](https://sea2.discourse-cdn.com/flex020/user_avatar/forums.knack.com/michaelg/32/758_2.png) [@MichaelG](https://forums.knack.com/u/MichaelG)\
**Post date:** [June 7, 2022, 9:26am UTC](https://forums.knack.com/t/if-name-is-true-or-if-role-is-true-contained-the-role/12640/9 "2022-06-07T09:26:18Z")

</div>

I was using the Users object instead of the role object. Ok, changed it.  
Still does not work.

$(document).on(‘knack-view-render.view\_265’, function(event, view, data) {  
$(’#view\_265 div.kn-details-link’).hide();  
var LoggedInUser = (Knack.getUserAttributes().name);  
var Responsible = $(’#view\_265 div.kn-detail.field\_271 \> div.kn-detail-body’).text();  
if(LoggedInUser === Responsible) { $(’#view\_265 div.kn-details-link’).show(); }  
else if(Knack.getUserAttributes().roles.indexOf(‘object\_5’)\>0) { $(’#view\_265 div.kn-details-link’).show();  
} ;  
});

 ![image](https://us1.discourse-cdn.com/flex020/uploads/knack/original/2X/a/a5815edef57095bda595be273d1e438cffe16edd.png)

---

<div class="post-metadata">

**Author:** ![Sunny\_Singla](https://sea2.discourse-cdn.com/flex020/user_avatar/forums.knack.com/sunny_singla/32/1007_2.png) [@Sunny\_Singla](https://forums.knack.com/u/Sunny_Singla)\
**Post date:** [June 7, 2022, 11:39am UTC](https://forums.knack.com/t/if-name-is-true-or-if-role-is-true-contained-the-role/12640/10 "2022-06-07T11:39:32Z")

</div>

You need to create a Role.

and assign that role to logged in user.

For any professional help, you can mail me.

Screenshot show that it’s not a Role it’s a simple object

Regards,  
Sunny Singla  
[ssingla1985@gmail.com](mailto:ssingla1985@gmail.com)

---

<div class="post-metadata">

**Author:** ![MichaelG](https://sea2.discourse-cdn.com/flex020/user_avatar/forums.knack.com/michaelg/32/758_2.png) [@MichaelG](https://forums.knack.com/u/MichaelG)\
**Post date:** [June 7, 2022, 12:03pm UTC](https://forums.knack.com/t/if-name-is-true-or-if-role-is-true-contained-the-role/12640/11 "2022-06-07T12:03:21Z")

</div>

I do have the Coordinator role which is assigned to the corresponding users.

If you say that for the object icon, I notified Knack support 2 weeks ago to better have a user icon when it is a Role.

 ![image](https://us1.discourse-cdn.com/flex020/uploads/knack/original/2X/2/2e9563c12b8071ea3325cce0315d006d348a31ad.png)

---

<div class="post-metadata">

**Author:** ![Sunny\_Singla](https://sea2.discourse-cdn.com/flex020/user_avatar/forums.knack.com/sunny_singla/32/1007_2.png) [@Sunny\_Singla](https://forums.knack.com/u/Sunny_Singla)\
**Post date:** [June 7, 2022, 12:33pm UTC](https://forums.knack.com/t/if-name-is-true-or-if-role-is-true-contained-the-role/12640/12 "2022-06-07T12:33:31Z")

</div>

first check → Knack.getUserAttributes().roles

then check if it contain roles of that object or not.

Then check url of this role and use that id.

---

<div class="post-metadata">

**Author:** ![MichaelG](https://sea2.discourse-cdn.com/flex020/user_avatar/forums.knack.com/michaelg/32/758_2.png) [@MichaelG](https://forums.knack.com/u/MichaelG)\
**Post date:** [June 7, 2022, 2:45pm UTC](https://forums.knack.com/t/if-name-is-true-or-if-role-is-true-contained-the-role/12640/13 "2022-06-07T14:45:53Z")

</div>

Thanks Sunny. I will follow this structure.

Tell you soon.

---

<div class="post-metadata">

**Author:** ![MichaelG](https://sea2.discourse-cdn.com/flex020/user_avatar/forums.knack.com/michaelg/32/758_2.png) [@MichaelG](https://forums.knack.com/u/MichaelG)\
**Post date:** [July 6, 2022, 5:23pm UTC](https://forums.knack.com/t/if-name-is-true-or-if-role-is-true-contained-the-role/12640/14 "2022-07-06T17:23:03Z")

</div>

@Sunny_Singla , at the end I got this one!

I had left it alone to work on styling issues, and looking at it again today with a fresh look I discovered 2 things very fast:  
a) for some reason, I wasn’t using the normal coding single quotation marks,  
b) I changed the page access to all users.

And now works perfectly! THANK YOU Very much!
