locked
Hide export button based on role RRS feed

  • Question

  • hi folks!
    Im trying to hide export to excel button based on security roles via following code but it's not working.

    I have added the requiered enable rule to the command via Ribbon workbench. Can you tell me where i am wrong ?

    function ShowHideExport2Excel(SelectedEntityTypeName) {

    var userid = Xrm.Page.context.getUserId(); var req = new XMLHttpRequest(); req.open("GET", Xrm.Page.context.getClientUrl() + "/api/data/v8.1/systemusers("+userid.slice(1,-1)+")?$expand=systemuserroles_association($select=name)", false); req.setRequestHeader("OData-MaxVersion", "4.0"); req.setRequestHeader("OData-Version", "4.0"); req.setRequestHeader("Accept", "application/json"); req.setRequestHeader("Content-Type", "application/json; charset=utf-8"); req.setRequestHeader("Prefer", "odata.include-annotations=\"*\""); req.onreadystatechange = function() { if (this.readyState === 4) { req.onreadystatechange = null; if (this.status === 200) { var result = JSON.parse(this.response); var systemuserid = result["systemuserid"]; for (var a = 0; a < result.systemuserroles_association.length; a++) { var systemuserroles_association_name = result.systemuserroles_association[a]["name"]; if (systemuserroles_association_name == "Sales") { debugger; if (SelectedEntityTypeName == "opportunity" || SelectedEntityTypeName == "activitypointer" || SelectedEntityTypeName == "appointment" || SelectedEntityTypeName == "account" || SelectedEntityTypeName == "quote"){ return false; // hide button } else { return true; //show button } } } } else { Xrm.Utility.alertDialog(this.statusText); } } }; req.send(); }



    • Edited by Eldanar Tuesday, January 24, 2017 5:59 PM
    Tuesday, January 24, 2017 10:44 AM

All replies