locked
CRM 2011 Disable section RRS feed

  • Question

  • Hello!

    I would like to set a section to disabled. The section contains one webresource which is a silverlight component. I can't hide it because it shows important information to other users. I'd like to make it disabled for other users other than the owner. I couldn't found any solution how to disable this section. 

    Can anybody tell me if this is possible?

    Thanks!

    function Disable() {
        var ownerUser = Xrm.Page.getAttribute('ownerid').getValue();
        var currentUser = Xrm.Page.context.getUserId();
        if (ownerUser[0].id != currentUser) {
            var tabSections = Xrm.Page.ui.tabs.get(3).sections.get();
            for (var i in tabSections) {
                var sectionLabel = tabSections[i].getLabel();
                if (sectionLabel == 'LinkekDataGrid') {
                    tabSections[i].setVisible(false);
                  
                }
            }
     }


    • Edited by Lénárd Friday, December 14, 2012 9:17 AM
    Friday, December 14, 2012 8:41 AM

Answers

  • hi lenard,

    you can only perform there operations to sections. 

    Method Description

    getLabel

    Returns the label for the section.

    getName

    Returns the name of the section.

    getParent

    Returns the tab containing the section.

    getVisible

    Returns a value that indicates whether the section is visible.

    setLabel

    Sets the label for the section.

    setVisible

    Sets a value that indicates whether the section is visible. 

     

    methods description by _Vikram in this post.


    Thanks and Regards. Make sure to "Vote as Helpful" and "Mark As Answer",if you get answer of your question.


    • Edited by Ravitheja J Friday, December 14, 2012 10:53 AM
    • Marked as answer by Lénárd Friday, December 14, 2012 10:56 AM
    Friday, December 14, 2012 10:53 AM

All replies

  • // JScript source code function onLoad() { if(!UserHasRole("System Administrator")) //Please { // do something important var section = crmForm.all.new_attribute_c.parentElement.parentElement.parentElement; for (i = 0; i < section.all.length; i++) { section.all[i].Disabled = true; } } //You replace new_attribute with the name of an attribute that resides inside the section you wish to disable. } function UserHasRole(roleName) { var serverUrl = Xrm.Page.context.getServerUrl(); var oDataEndpointUrl = serverUrl + "/XRMServices/2011/OrganizationData.svc/"; oDataEndpointUrl += "RoleSet?$top=1&$filter=Name eq '" + roleName + "'"; var service = GetRequestObject(); if (service != null) { service.open("GET", oDataEndpointUrl, false); service.setRequestHeader("X-Requested-Width", "XMLHttpRequest"); service.setRequestHeader("Accept", "application/json, text/javascript, */*"); service.send(null); var requestResults = eval('(' + service.responseText + ')').d; if (requestResults != null && requestResults.length == 1) { var role = requestResults[0]; var id = role.RoleId; var currentUserRoles = Xrm.Page.context.getUserRoles(); for (var i = 0; i < currentUserRoles.length; i++) { var userRole = currentUserRoles[i]; if (GuidsAreEqual(userRole, id)) { return true; } } } } return false; } function GetRequestObject() { if (window.XMLHttpRequest) { return new window.XMLHttpRequest; } else { try { return new ActiveXObject("MSXML2.XMLHTTP.3.0"); } catch (ex) { return null; } } } function GuidsAreEqual(guid1, guid2) { var isEqual = false; if (guid1 == null || guid2 == null) { isEqual = false; } else { isEqual = guid1.replace(/[{}]/g, "").toLowerCase() == guid2.replace(/[{}]/g, "").toLowerCase(); } return isEqual; }

    Please check the above code and you only required to change the user role and schema name of section.
    For more references please check following blog.
     


    I hope this helps. If my response answered your question, please mark the response as an answer and also vote as helpful.
    Mubasher Sharif
    Check out my about.me profile!
    http://mubashersharif.blogspot.com
    Linked-In Profile
    Follow me on Twitter!


    Friday, December 14, 2012 9:47 AM
  • hi lenard,

    you can only perform there operations to sections. 

    Method Description

    getLabel

    Returns the label for the section.

    getName

    Returns the name of the section.

    getParent

    Returns the tab containing the section.

    getVisible

    Returns a value that indicates whether the section is visible.

    setLabel

    Sets the label for the section.

    setVisible

    Sets a value that indicates whether the section is visible. 

     

    methods description by _Vikram in this post.


    Thanks and Regards. Make sure to "Vote as Helpful" and "Mark As Answer",if you get answer of your question.


    • Edited by Ravitheja J Friday, December 14, 2012 10:53 AM
    • Marked as answer by Lénárd Friday, December 14, 2012 10:56 AM
    Friday, December 14, 2012 10:53 AM
  • HI CRMIG!

    Thanks for your replay. 

    Is there any other way to disable a webresouce? 

    Friday, December 14, 2012 10:58 AM