24. Januar 2011 13:28
if ( ABFRAGE BESITZER || ABFRAGE ROLLE ) {
crmForm.all.tab4Tab.style.display = "none";
}
24. Januar 2011 13:48
24. Januar 2011 13:52
Michael Sulz hat geschrieben:wie ermittelst du denn, ob der Benutzer der Besitzer des Datensatzes ist, bzw. welche Rolle dem Benutzer zugewiesen sind?
Michael Sulz hat geschrieben:Bitte denke auch daran, dass das Ausblenden von Tabs nur auf dem Formular wirksam ist, in der erweiterten Suche oder Reports werden diese Felder trotzdem angezeigt.
24. Januar 2011 15:19
Michael Sulz hat geschrieben:
wie ermittelst du denn, ob der Benutzer der Besitzer des Datensatzes ist, bzw. welche Rolle dem Benutzer zugewiesen sind?Genau diese Abfrage erhoffe ich hier im Forum zu finden... Ist es nicht möglich, abzufragen welche Rolle der User gerade inne hat oder ob er der Besitzer des Kontakts ist?
Nein, das geht nicht mit einer einfachen Programmierung. Du kannst natürlich ein Programm schreiben, das den Request des Servers abfängt und dann entsprechend deinen Anforderungen wieder zusammenbaut, das ist aber sehr aufwendig.Michael Sulz hat geschrieben:
Bitte denke auch daran, dass das Ausblenden von Tabs nur auf dem Formular wirksam ist, in der erweiterten Suche oder Reports werden diese Felder trotzdem angezeigt.Kann ich die erweiterte Suche bzw. die angebotenen Reports dahingehend nicht einschränken?
31. Januar 2011 12:10
31. Januar 2011 14:57
Hide Fields or Tabs by Role with Javascript
By Carlton Colter - Last updated: Wednesday, September 30, 2009 - Save & Share - 9 Comments
Here are a set of methods to assist in hiding tabs or sections based on role, it is a modified version of Jimmy Wang’s version.
First, we need a set of functions to facilitate our our process. We need to get the roles of the current user, GetCurrentUserRoles. Then we need to see if the user has the role, UserHasRole. Finally we can hide the fields (HideFieldByRole) or tabs (HideTabByRole).
GetCurrentUserRoles
The first thing we need to do is get a list of roles according to the current user. There are a couple of different ways to do this. You could use the RemoteCommand to get the current user and then their roles, a blog post by Zahara Hirani on Hide Show Fields in CRM 4 based on security role outlines this. However, I do not want to make multiple request for the same information. I want to get the roles for the current user in one line. Below shows the GetCurrentUserRoles that implements a RetrieveMultiple query to get the names of the roles that a user has in one request.
view plaincopy to clipboardprint?
function GetCurrentUserRoles()
1. {
var xml = "" +
2. "<?xml version=\"1.0\" encoding=\"utf-8\"?>" +
"<soap:Envelope xmlns:soap=\"" +
3. "http://schemas.xmlsoap.org/soap/envelope/" +
"\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"" +
4. " xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\">" +
GenerateAuthenticationHeader() +
5. " <soap:Body>" +
" <RetrieveMultiple xmlns=\"" +
6. "http://schemas.microsoft.com/crm/2007/WebServices\">" +
" <query xmlns:q1=\"" +
7. "http://schemas.microsoft.com/crm/2006/Query" +
"\" xsi:type=\"q1:QueryExpression\">" +
8. " <q1:EntityName>role</q1:EntityName>" +
" <q1:ColumnSet xsi:type=\"q1:ColumnSet\">" +
9. " <q1:Attributes>" +
" <q1:Attribute>name</q1:Attribute>" +
10. " </q1:Attributes>" +
" </q1:ColumnSet>" +
11. " <q1:Distinct>false</q1:Distinct>" +
" <q1:LinkEntities>" +
12. " <q1:LinkEntity>" +
" <q1:LinkFromAttributeName>roleid</q1:LinkFromAttributeName>" +
13. " <q1:LinkFromEntityName>role</q1:LinkFromEntityName>" +
" <q1:LinkToEntityName>systemuserroles</q1:LinkToEntityName>" +
14. " <q1:LinkToAttributeName>roleid</q1:LinkToAttributeName>" +
" <q1:JoinOperator>Inner</q1:JoinOperator>" +
15. " <q1:LinkEntities>" +
" <q1:LinkEntity>" +
16. " <q1:LinkFromAttributeName>systemuserid</q1:LinkFromAttributeName>" +
" <q1:LinkFromEntityName>systemuserroles</q1:LinkFromEntityName>" +
17. " <q1:LinkToEntityName>systemuser</q1:LinkToEntityName>" +
" <q1:LinkToAttributeName>systemuserid</q1:LinkToAttributeName>" +
18. " <q1:JoinOperator>Inner</q1:JoinOperator>" +
" <q1:LinkCriteria>" +
19. " <q1:FilterOperator>And</q1:FilterOperator>" +
" <q1:Conditions>" +
20. " <q1:Condition>" +
" <q1:AttributeName>systemuserid</q1:AttributeName>" +
21. " <q1:Operator>EqualUserId</q1:Operator>" +
" </q1:Condition>" +
22. " </q1:Conditions>" +
" </q1:LinkCriteria>" +
23. " </q1:LinkEntity>" +
" </q1:LinkEntities>" +
24. " </q1:LinkEntity>" +
" </q1:LinkEntities>" +
25. " </query>" +
" </RetrieveMultiple>" +
26. " </soap:Body>" +
"</soap:Envelope>" +
27. "";
28. var xmlHttpRequest = new ActiveXObject("Msxml2.XMLHTTP");
29. xmlHttpRequest.Open("POST", "/mscrmservices/2007/CrmService.asmx", false);
xmlHttpRequest.setRequestHeader("SOAPAction",
30. " http://schemas.microsoft.com/crm/2007/WebServices/RetrieveMultiple");
xmlHttpRequest.setRequestHeader("Content-Type", "text/xml; charset=utf-8");
31. xmlHttpRequest.setRequestHeader("Content-Length", xml.length);
xmlHttpRequest.send(xml);
32.
var resultXml = xmlHttpRequest.responseXML;
33. return(resultXml);
}
The next method is a simple method for searching the XML result from GetCurrentUserRoles. By passing it the roles you are looking for and the roles the user has, it will determine if there is a match. The roles it is passed is separated by a pipe (|).
view plaincopy to clipboardprint?
function UserHasRole(roleNames, rolesXML)
1. {
// split roleNames on pipe
2. var matchon = roleNames.split('|');
3. if(rolesXML != null)
{
4. //select the node text
var roles = rolesXML.selectNodes("//BusinessEntity/q1:name");
5. if(roles != null)
{
6. for( i = 0; i < roles.length; i++)
{
7. for (j = 0; j < matchon.length; j++)
{
8. // If there is a match, return true, found
if (roles[i].text == matchon[j]) return true;
9. }
}
10. }
}
11. //otherwise return false
return false;
12. }
Finally, we can now implement helper methods to allow the hiding of a tab or a field if a user DOES NOT have a specific role.
view plaincopy to clipboardprint?
function HideTabByRole(role, roles, tabnumber)
1. // Tab number starts on 0
{
2. var tab = document.getElementById('tab'+tabnumber+'Tab');
var usrRole = UserHasRole(role, roles);
3. if(!usrRole)
{
4. tab.style.display = "none";
}
5. }
6. function HideFieldByRole(role, roles, field,cfield,dfield)
{
7. var usrRole = UserHasRole(role, roles);
if(!usrRole)
8. {
field.style.visibility = 'hidden';
9. field.style.position = 'absolute';
cfield.style.visibility = 'hidden';
10. cfield.style.position = 'absolute';
dfield.visibility = 'hidden';
11. dfield.style.position = 'absolute';
}
12. }
To implement this process, all you have to do is put every piece of code in this article inside your onload with the following customized for your situation.
view plaincopy to clipboardprint?
var UserRoles = GetCurrentUserRoles();
1.
HideTabByRole('Account Managers|SystemAdministrators', UserRoles, 3);
2.
HideFieldByRole('Account Managers', UserRoles,
3. crmForm.all.parentcustomerid,
crmForm.all.parentcustomerid_c,
4. crmForm.all.parentcustomerid_d);
If you have any questions of problems implementing this in your environment, please let me know, and I’ll do my best to help you get it working>