
17. September 2018 — Miss Ob·so·let
Microsoft Dynamics CRM: How to find out if user is member of a team
I want to check, if the user is member of a special team. If he is member of the team, I want to show some tabs. If the user is not a member of this team, I want to hide the tabs.
Use following Javascript to check, weather the current user is member of the A-Team:
function CFTabs() { var teamName = 'A-Team'; var ClientUrl = Xrm.Page.context.getClientUrl(); checkTeam('A-Team'); function checkTeam(teamName) { var clientURL = Xrm.Page.context.getClientUrl(); var req = new XMLHttpRequest(); var userId = Xrm.Page.context.getUserId(); userId = userId.replace("{", ""); userId = userId.replace("}", ""); var query = "/api/data/v8.2/systemusers(" + userId + ")?$expand=teammembership_association($select=name;$filter=name eq '" + teamName + "')"; req.open("GET", encodeURI(clientURL + query), false); req.setRequestHeader("Accept", "application/json"); req.setRequestHeader("Content-Type", "application/json;charset=utf-8"); req.setRequestHeader("OData-MaxVersion", "4.0"); req.setRequestHeader("OData-Version", "4.0"); req.send(); if (req.status == 200) { var data = JSON.parse(req.response).teammembership_association; if (data.length > 0) { Xrm.Page.ui.tabs.get("TAB1").setVisible(true); Xrm.Page.ui.tabs.get("TAB2").setVisible(true); Xrm.Page.ui.tabs.get("TAB3").setVisible(true); } else { Xrm.Page.ui.tabs.get("TAB1").setVisible(false); Xrm.Page.ui.tabs.get("TAB2").setVisible(false); Xrm.Page.ui.tabs.get("TAB3").setVisible(false); } } } }
You can also use array of teams:
function CFTabs() { var teamName = ['A-Team', 'B-Team', 'C-Team', 'D-Team']; for (i = 0; i <= teamName.length; i++) { var ClientUrl = Xrm.Page.context.getClientUrl(); var clientURL = Xrm.Page.context.getClientUrl(); var req = new XMLHttpRequest(); var userId = Xrm.Page.context.getUserId(); userId = userId.replace("{", ""); userId = userId.replace("}", ""); var query = "/api/data/v8.2/systemusers(" + userId + ")?$expand=teammembership_association($select=name;$filter=name eq '" + teamName[i] + "')"; req.open("GET", encodeURI(clientURL + query), false); req.setRequestHeader("Accept", "application/json"); req.setRequestHeader("Content-Type", "application/json;charset=utf-8"); req.setRequestHeader("OData-MaxVersion", "4.0"); req.setRequestHeader("OData-Version", "4.0"); req.send(); var data = JSON.parse(req.response).teammembership_association; if (data.length > 0) { Xrm.Page.ui.tabs.get("TAB1").setVisible(true); Xrm.Page.ui.tabs.get("TAB2").setVisible(true); Xrm.Page.ui.tabs.get("TAB3").setVisible(true); return; } else { Xrm.Page.ui.tabs.get("TAB1").setVisible(false); Xrm.Page.ui.tabs.get("TAB2").setVisible(false); Xrm.Page.ui.tabs.get("TAB3").setVisible(false); } } }
Share it:
- Click to share on WhatsApp (Opens in new window)
- Click to share on Facebook (Opens in new window)
- Click to share on Twitter (Opens in new window)
- Click to share on Pinterest (Opens in new window)
- Click to email this to a friend (Opens in new window)
- More
- Click to share on LinkedIn (Opens in new window)
- Click to share on Tumblr (Opens in new window)
- Click to print (Opens in new window)
- Click to share on Reddit (Opens in new window)
- Click to share on Telegram (Opens in new window)
- Click to share on Skype (Opens in new window)
- Click to share on Pocket (Opens in new window)
Related
About Miss Ob·so·let
Imperfection is beauty, madness is genious. it is better to be absolutely ridiculous than absolutely boring.Latest Posts By Miss Ob·so·let
- 01.15.21until the end
- 01.10.21Caorle
- 11.02.20nothing that grieves us can be called little. by the eternal laws of proportion a child’s loss of a doll and a king’s loss of a crown are events of the same size.
- 10.16.20By all means let's be open-minded, but not so open-minded that our brains drop out.
- 10.15.20Invictus