Need Access to User's Group OR Membership name to build a Dynamic Link

Dan McDevitt asked on September 11, 2019 17:27

I'm the web developer for a professional organization with chapters around the US. The chapters are represented in our CMS database as Groups, and the members are connected to the Groups by being in a group role. This works well for most of our needs.

We have a repeater on our website's home page that displays content from the user's chapter (if they are a member), which works fine connecting through their group role as described above. But I also need to display a dynamic link to the chapter page on our site based on the user. For example, if the user is a member of the Chicago chapter, along with the two most recent news items from that chapter there should be a "See All" link to the Chicago chapter news page. The link is in the HTML envelope and looks like this:

[a href="/Network/Chapters/{% //DYNAMIC CHAPTER PATH HERE// #%}/News.aspx"]See All [/a]

I'm stuck trying to generate that dynamic path. I thought the simplest thing would be to pull the group from the CurrentUser object. Each user has only one group. However, CurrentUser.ReferringObjects.Groups is empty. I thought perhaps this was because the user wasn't a member of the group, only in the group role, but I modified the system to add the user to the group directly and it still doesn't work.

My second attempt was to go through the GroupMembers collection: CurrentUser.ReferringObjects.GroupMembers That at least has an entry in it, but that entry is only the data from the Community_GroupMember table and doesn't include the group name itself.

Thinking the problem was with groups, I also set up a membership for the chapter and added that membership for the member, and tried similar tactics. The result was the same; I can get the MembershipUser information but nothing from the Membership object itself.

I honestly don't care if I use Groups or Memberships; either one is fine. I just need a way to get information about the group or membership the user is connected to so I can build a dynamic path to the appropriate chapter page. I've been working on this for some time with no success.

Thanks in Advance.

Recent Answers


Brenden Kehren answered on September 11, 2019 23:20

If you use memberships, you can use a macro like:

CurrentUser.Memberships.FirstItem.DisplayName

Groups are a bit harder to work with.

0 votesVote for this answer Mark as a Correct answer

Dan McDevitt answered on September 11, 2019 23:59

Brenden, Thanks. I tried that, but it doesn't return anything. If I pull CurrentUser.Membership.Count (just for the sake of analyzing the problem), it returns 0,despite the logged-in user having a membership record. I don't know why that is, but it's got to be where the problem lies. I create the membership records programmatically when they log in, but I've also tried it with a membership created through the administration portal.

If I use CurrentUser.OtherBindings.MembershipUsers.FirstItem.DisplayName, I get a result, but the it's the display name of the MembershipUser record: cms.membershipuser%20(4). So the system knows this user has a membership, but I can't access the information about it.

-Dan

0 votesVote for this answer Mark as a Correct answer

Brenden Kehren answered on September 12, 2019 00:18

Are you sure you have all your fields filled out when you're creating the membership?

0 votesVote for this answer Mark as a Correct answer

Dan McDevitt answered on September 12, 2019 16:35

Yes, I've gone through every permutation of that I can think of. The only required fields in a MembershipUser record are MembershipID and UserID. I considered that when I created the record programmatically some key piece of data was missing, so I tried creating one manually with the same result.

Is there any possibility that the CurrentUser object could be where the problem lies? Our code doesn't do anything particular to initiate that object when the user logs in, we're using standard windows forms authentication. If there's any other step that's necessary to ensure the CurrentUser object has all the right connections I'll need to add it.

0 votesVote for this answer Mark as a Correct answer

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