Tuesday, November 8, 2011

Hide control "Est. Revenue" on Opportunity form

If you want to hide "Est. Revenue" field for all except special CRM role and owner of this opportunity you can use following javascript code:
function GetCurrentUserRoles()
{
 var xml = "" +
"" +
"" +
GenerateAuthenticationHeader() +
" " +
" " +
" " +
" role" +
" " +
" " +
" name" +
" " +
" " +
" false" +
" " +
" " +
" roleid" +
" role" +
" systemuserroles" +
" roleid" +
" Inner" +
" " +
" " +
" systemuserid" +
" systemuserroles" +
" systemuser" +
" systemuserid" +
" Inner" +
" " +
" And" +
" " +
" " +
" systemuserid" +
" EqualUserId" +
" " +
" " +
" " +
" " +
" " +
" " +
" " +
" " +
" " +
" " +
"" +
"";
 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);
}


function hideRevenue()
{
 UserID = Xrm.Page.context.getUserId();
 OwnerID = Xrm.Page.getAttribute("ownerid").getValue()[0].id;
 if (UserHasRole("Boss") || UserID == OwnerID)
 {
  Xrm.Page.ui.controls.get("estimatedvalue").setVisible(true);
 }
 else
 {
  Xrm.Page.ui.controls.get("estimatedvalue").setVisible(false);
 }
}

2 comments:

  1. With integrity, you have nothing to fear, since you have nothing to hide. With integrity, you will do the right thing, so you will have no guilt. See the link below for more info.


    #hide
    www.ufgop.org

    ReplyDelete
  2. I really love your blog there's a lot to share. Keep it up.Visit my site too.

    n8fan.net

    www.n8fan.net

    ReplyDelete