Compare two macros and give true value?

Jon White asked on October 5, 2015 17:13

Hi there,

This is kind of related to my last post about role permissions. Due to complicated permissions and structure (on an intranet) I want those who are in the same role as the person who posted a document to see the edit contribution buttons or other bits on a template more dynamically (as i'm using one global template), this is so not just the 'page owner' can make amends, but others in the same department.

I figured this could be done with macros and comparing page owner role with the current user role value and put the 'true/false' result in the 'visibility' part of the webpart. these are the macros:

{% CurrentDocument.DocumentCreatedByUser.OtherBindings.UserRoles.FieldsAsObjects.RoleID.DisplayNames #%}

&

{% CurrentUser.OtherBindings.UserRoles.FieldsAsObjects.RoleID.DisplayNames #%}

Does anyone know what the expression would be to check one against the other and if true show "true" etc..?

The added problem is that some people have more than one role so really i guess i need a "includes ###" in the string.

Thank you in advance. Jon

Recent Answers


Brenden Kehren answered on October 5, 2015 17:25 (last edited on December 10, 2019 02:30)

It would look something like this:

{% If(CurrentDocument.DocumentCreatedByUser.OtherBindings.UserRoles.FieldsAsObjects.RoleID.DisplayNames == CurrentUser.OtherBindings.UserRoles.FieldsAsObjects.RoleID.DisplayNames){true}else{false} |(identity)GlobalAdministrator%}
0 votesVote for this answer Mark as a Correct answer

Jon White answered on October 5, 2015 17:39 (last edited on December 10, 2019 02:30)

Thanks Brenden, this looks like is should work (similar to what i had tried), but I keep getting a false result.

I've put them separately to check the values are correct: {%CurrentDocument.DocumentCreatedByUser.OtherBindings.UserRoles.FieldsAsObjects.RoleID.DisplayNames |(identity)GlobalAdministrator%}

0 votesVote for this answer Mark as a Correct answer

Brenden Kehren answered on October 5, 2015 20:59

Have you tried turning on Macro debugging? You can find out what the values are returning and why it's returning false.

0 votesVote for this answer Mark as a Correct answer

Joshua Adams answered on October 6, 2015 15:07 (last edited on December 10, 2019 02:30)

You could try a ternary condition:

{% (CurrentUser.OtherBindings.UserRoles.FieldsAsObjects.RoleID.DisplayNames == CurrentUser.OtherBindings.UserRoles.FieldsAsObjects.RoleID.DisplayNames)? true : false |(identity)GlobalAdministrator%}

For some reason the if statements don't seem to work for me usually.

0 votesVote for this answer Mark as a Correct answer

   Please, sign in to be able to submit a new answer.