Answered by:
Script to hide Tab does not work

Question
-
Hi,
I have CRM 3.0 and I am trying to hide two tabs (No 4 and 3 on the form) on the Opportunity window based on security role.
I have included the below script on the OnLoad event on the form and also activated the event. However, the tabs show up for everybody - implying the script is not working. I receive no errors. Any help will be appreciated. Thank you for your time.
Jack
----------------------------------------
function UserHasRole(roleName)
{
//get Current User Roles, oXml is an object
var oXml = GetCurrentUserRoles();
if(oXml != null)
{
//select the node text
var roles = oXml.selectNodes("//BusinessEntity/q1:name");
if(roles != null)
{
for( i = 0; i < roles.length; i++)
{
if(roles[i].text == roleName)
{
//return true if user has this role
return true;
}
}
}
}
//otherwise return falsereturn false;
}function GetCurrentUserRoles()
{
var xml = "" +
"<?xml version=\"1.0\" encoding=\"utf-8\"?>" +
"<soap:Envelope xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\">" +
GenerateAuthenticationHeader() +
" <soap:Body>" +
" <RetrieveMultiple xmlns=\"http://schemas.microsoft.com/crm/2007/WebServices\">" +
" <query xmlns:q1=\"http://schemas.microsoft.com/crm/2006/Query\" xsi:type=\"q1:QueryExpression\">" +
" <q1:EntityName>role</q1:EntityName>" +
" <q1:ColumnSet xsi:type=\"q1:ColumnSet\">" +
" <q1:Attributes>" +
" <q1:Attribute>name</q1:Attribute>" +
" </q1:Attributes>" +
" </q1:ColumnSet>" +
" <q1:Distinct>false</q1:Distinct>" +
" <q1:LinkEntities>" +
" <q1:LinkEntity>" +
" <q1:LinkFromAttributeName>roleid</q1:LinkFromAttributeName>" +
" <q1:LinkFromEntityName>role</q1:LinkFromEntityName>" +
" <q1:LinkToEntityName>systemuserroles</q1:LinkToEntityName>" +
" <q1:LinkToAttributeName>roleid</q1:LinkToAttributeName>" +
" <q1:JoinOperator>Inner</q1:JoinOperator>" +
" <q1:LinkEntities>" +
" <q1:LinkEntity>" +
" <q1:LinkFromAttributeName>systemuserid</q1:LinkFromAttributeName>" +
" <q1:LinkFromEntityName>systemuserroles</q1:LinkFromEntityName>" +
" <q1:LinkToEntityName>systemuser</q1:LinkToEntityName>" +
" <q1:LinkToAttributeName>systemuserid</q1:LinkToAttributeName>" +
" <q1:JoinOperator>Inner</q1:JoinOperator>" +
" <q1:LinkCriteria>" +
" <q1:FilterOperator>And</q1:FilterOperator>" +
" <q1:Conditions>" +
" <q1:Condition>" +
" <q1:AttributeName>systemuserid</q1:AttributeName>" +
" <q1:Operator>EqualUserId</q1:Operator>" +
" </q1:Condition>" +
" </q1:Conditions>" +
" </q1:LinkCriteria>" +
" </q1:LinkEntity>" +
" </q1:LinkEntities>" +
" </q1:LinkEntity>" +
" </q1:LinkEntities>" +
" </query>" +
" </RetrieveMultiple>" +
" </soap:Body>" +
"</soap:Envelope>" +
"";var xmlHttpRequest = new ActiveXObject("Msxml2.XMLHTTP");
xmlHttpRequest.Open("POST", "/mscrmservices/2007/CrmService.asmx", false);
xmlHttpRequest.setRequestHeader("SOAPAction"," http://schemas.microsoft.com/crm/2007/WebServices/RetrieveMultiple");
xmlHttpRequest.setRequestHeader("Content-Type", "text/xml; charset=utf-8");
xmlHttpRequest.setRequestHeader("Content-Length", xml.length);
xmlHttpRequest.send(xml);var resultXml = xmlHttpRequest.responseXML;
return(resultXml);
}if (!UserHasRole("System Administrator"))
{
crmForm.all.tab4Tab.style.display="none";
crmForm.all.tab3Tab.style.visibility = "hidden";
}Monday, January 17, 2011 11:08 PM
Answers
-
Hi Jack,
For CRM 3.0, the JScript could be something like this (remember that Tabs begins in "0", so the third tab is tab2Tab and the fourth one is tab3Tab):if (UserHasRole("System Administrator"))
{
crmForm.all.tab2Tab.style.display="none";
crmForm.all.tab3Tab.style.display="none";
}
Check these articles for CRM 3.0http://social.microsoft.com/Forums/en-US/crm/thread/ce80ff4e-21a1-4b66-8e47-7926f2dc80da
http://social.microsoft.com/forums/en-US/crmdevelopment/thread/487e5292-331f-4c78-8876-78127e939472/
Julio- Proposed as answer by Julio Luque Cuba Wednesday, January 19, 2011 2:14 PM
- Marked as answer by DavidJennawayMVP, Moderator Friday, February 11, 2011 6:13 PM
Tuesday, January 18, 2011 2:02 PM
All replies
-
Hi,
I have CRM 3.0 and I am trying to hide two tabs (No 4 and 3 on the form) on the Opportunity window based on security role.
I have included the below script on the OnLoad event on the form and also activated the event. However, the tabs show up for everybody - implying the script is not working. I receive no errors. Any help will be appreciated. Thank you.
Jack
----------------------------------------
function UserHasRole(roleName)
{
//get Current User Roles, oXml is an object
var oXml = GetCurrentUserRoles();
if(oXml != null)
{
//select the node text
var roles = oXml.selectNodes("//BusinessEntity/q1:name");
if(roles != null)
{
for( i = 0; i < roles.length; i++)
{
if(roles[i].text == roleName)
{
//return true if user has this role
return true;
}
}
}
}
//otherwise return falsereturn false;
}function GetCurrentUserRoles()
{
var xml = "" +
"<?xml version=\"1.0\" encoding=\"utf-8\"?>" +
"<soap:Envelope xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\">" +
GenerateAuthenticationHeader() +
" <soap:Body>" +
" <RetrieveMultiple xmlns=\"http://schemas.microsoft.com/crm/2007/WebServices\">" +
" <query xmlns:q1=\"http://schemas.microsoft.com/crm/2006/Query\" xsi:type=\"q1:QueryExpression\">" +
" <q1:EntityName>role</q1:EntityName>" +
" <q1:ColumnSet xsi:type=\"q1:ColumnSet\">" +
" <q1:Attributes>" +
" <q1:Attribute>name</q1:Attribute>" +
" </q1:Attributes>" +
" </q1:ColumnSet>" +
" <q1:Distinct>false</q1:Distinct>" +
" <q1:LinkEntities>" +
" <q1:LinkEntity>" +
" <q1:LinkFromAttributeName>roleid</q1:LinkFromAttributeName>" +
" <q1:LinkFromEntityName>role</q1:LinkFromEntityName>" +
" <q1:LinkToEntityName>systemuserroles</q1:LinkToEntityName>" +
" <q1:LinkToAttributeName>roleid</q1:LinkToAttributeName>" +
" <q1:JoinOperator>Inner</q1:JoinOperator>" +
" <q1:LinkEntities>" +
" <q1:LinkEntity>" +
" <q1:LinkFromAttributeName>systemuserid</q1:LinkFromAttributeName>" +
" <q1:LinkFromEntityName>systemuserroles</q1:LinkFromEntityName>" +
" <q1:LinkToEntityName>systemuser</q1:LinkToEntityName>" +
" <q1:LinkToAttributeName>systemuserid</q1:LinkToAttributeName>" +
" <q1:JoinOperator>Inner</q1:JoinOperator>" +
" <q1:LinkCriteria>" +
" <q1:FilterOperator>And</q1:FilterOperator>" +
" <q1:Conditions>" +
" <q1:Condition>" +
" <q1:AttributeName>systemuserid</q1:AttributeName>" +
" <q1:Operator>EqualUserId</q1:Operator>" +
" </q1:Condition>" +
" </q1:Conditions>" +
" </q1:LinkCriteria>" +
" </q1:LinkEntity>" +
" </q1:LinkEntities>" +
" </q1:LinkEntity>" +
" </q1:LinkEntities>" +
" </query>" +
" </RetrieveMultiple>" +
" </soap:Body>" +
"</soap:Envelope>" +
"";var xmlHttpRequest = new ActiveXObject("Msxml2.XMLHTTP");
xmlHttpRequest.Open("POST", "/mscrmservices/2007/CrmService.asmx", false);
xmlHttpRequest.setRequestHeader("SOAPAction"," http://schemas.microsoft.com/crm/2007/WebServices/RetrieveMultiple");
xmlHttpRequest.setRequestHeader("Content-Type", "text/xml; charset=utf-8");
xmlHttpRequest.setRequestHeader("Content-Length", xml.length);
xmlHttpRequest.send(xml);var resultXml = xmlHttpRequest.responseXML;
return(resultXml);
}if (!UserHasRole("System Administrator"))
{
crmForm.all.tab4Tab.style.display="none";
crmForm.all.tab3Tab.style.visibility = "hidden";
}- Moved by Kimberlee Johnson Tuesday, January 18, 2011 12:28 AM Need help with code. (From:Dynamics CRM)
- Merged by DavidJennawayMVP, Moderator Friday, February 11, 2011 6:13 PM Duplicate thread
Monday, January 17, 2011 9:08 PM -
As you have CRM 3.0 therefore you should retreivemultiple crmService for crm 3. You will get it in the sdk of crm 3.0. It should be something like this:-
//var serverUrl = http://CrmServer;
//var spaymentdays = AccessCRMWebServices(id , serverUrl );
var serverUrl = "http://CrmServer/mscrmservices/2006";
var xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");xmlhttp.open("POST", serverUrl + "/crmservice.asmx", false);
xmlhttp.setRequestHeader("Content-Type", "text/xml; charset=utf-8");
xmlhttp.setRequestHeader("SOAPAction", "http://schemas.microsoft.com/crm/2006/WebServices/RetrieveMultiple")
xmlhttp.send("<?xml version='1.0' encoding='utf-8'?>"+"\n\n"+"<soap:Envelope"+
' xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"'+
' xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"'+
' xmlns:xsd="http://www.w3.org/2001/XMLSchema">'+
' <soap:Body>' +
' <query xmlns:q1="http://schemas.microsoft.com/crm/2006/Query" xsi:type="q1:QueryByAttribute" xmlns="http://schemas.microsoft.com/crm/2006/WebServices">'+
' <q1:EntityName>new_inspectionteammember</q1:EntityName>'+
Regards FaisalTuesday, January 18, 2011 1:08 PM -
Try below code and make sure that the tab Ids are correct and also the schema for crm 3 is different and your code as it is above will not work in crm3 as it is written for CRM4.
Check this post for CRM3
http://ronaldlemmen.blogspot.com/2006/05/finally-there-show-and-hide-fields.html
crmForm.all.tab3Tab.style.display= "none";
crmForm.all.tab4Tab.style.display="none";
Hope this helps. Amar
CRM Forum Guidance on how to Help Us Help You
- Proposed as answer by Faisal Fiaz Wednesday, January 19, 2011 9:09 AM
Tuesday, January 18, 2011 1:26 PM -
Hi Jack,
For CRM 3.0, the JScript could be something like this (remember that Tabs begins in "0", so the third tab is tab2Tab and the fourth one is tab3Tab):if (UserHasRole("System Administrator"))
{
crmForm.all.tab2Tab.style.display="none";
crmForm.all.tab3Tab.style.display="none";
}
Check these articles for CRM 3.0http://social.microsoft.com/Forums/en-US/crm/thread/ce80ff4e-21a1-4b66-8e47-7926f2dc80da
http://social.microsoft.com/forums/en-US/crmdevelopment/thread/487e5292-331f-4c78-8876-78127e939472/
Julio- Proposed as answer by Julio Luque Cuba Wednesday, January 19, 2011 2:14 PM
- Marked as answer by DavidJennawayMVP, Moderator Friday, February 11, 2011 6:13 PM
Tuesday, January 18, 2011 2:02 PM -
Have you tried to debug the script , if not try debugging the script and check the user role is retrieved properly..
Tuesday, January 18, 2011 5:45 PM -
Thank you. I have figured and fixed it.Tuesday, January 18, 2011 10:18 PM
-
Hello,
Thank you everyone for resolving this for me.
Jack
Tuesday, January 18, 2011 11:34 PM