Quantcast
Channel: CRM Development forum
Viewing all articles
Browse latest Browse all 8223

Unable to execute SOAP Request in CRM 2011 online

$
0
0

I am trying to execute a SOAP Request to check if the currently logged in user has some rights (e.g. say create Incidents). I am using the following piece of code.

if (typeof (SDK) == "undefined")
   { SDK = { __namespace: true }; }
       //This will establish a more unique namespace for functions in this library. This will reduce the 
       // potential for functions to be overwritten due to a duplicate name when the library is loaded.
       SDK.SOAP = {
           _getServerUrl: function () {
               ///<summary>
               /// Returns the URL for the SOAP endpoint using the context information available in the form
               /// or HTML Web resource.
               ///</summary>
               var ServicePath = "/XRMServices/2011/Organization.svc/web";
               var serverUrl = "";
               if (typeof GetGlobalContext == "function") {
                   var context = GetGlobalContext();
                   serverUrl = context.getServerUrl();
               }
               else {
                   if (typeof Xrm.Page.context == "object") {
                         serverUrl = Xrm.Page.context.getServerUrl();
                   }
                   else
                   { throw new Error("Unable to access the server URL"); }
                   }
                  if (serverUrl.match(/\/$/)) {
                       serverUrl = serverUrl.substring(0, serverUrl.length - 1);
                   } 
                   return serverUrl + ServicePath;
               }, 
           CheckUserPrivilegeRequest: function (privilegeName) {
               var requestXml = "<S:ENVELOPE xmlns:s=\"http://schemas.xmlsoap.org/soap/envelope/\">" +"  <S:BODY>" +"    <?XML:NAMESPACE PREFIX = [default] http://schemas.microsoft.com/xrm/2011/Contracts/Services NS = \"http://schemas.microsoft.com/xrm/2011/Contracts/Services\" /><retrievemultiple xmlns=\"http://schemas.microsoft.com/xrm/2011/Contracts/Services\" xmlns:i=\"http://www.w3.org/2001/XMLSchema-instance\">" +"      <query xmlns:a=\"http://schemas.microsoft.com/xrm/2011/Contracts\" i:type=\"a:QueryExpression\">" +"        <A:COLUMNSET>" +"          <A:ALLCOLUMNS>false</A:ALLCOLUMNS>" +"          <A:COLUMNS xmlns:b=\"http://schemas.microsoft.com/2003/10/Serialization/Arrays\">" +"        </A:COLUMNS></A:COLUMNSET>" +"        <A:CRITERIA>" +"          <A:CONDITIONS>" +"            <A:CONDITIONEXPRESSION>" +"              <A:ATTRIBUTENAME>name</A:ATTRIBUTENAME>" +"              <A:OPERATOR>Equal</A:OPERATOR>" +"              <A:VALUES xmlns:b=\"http://schemas.microsoft.com/2003/10/Serialization/Arrays\">" +"                <?xml:namespace prefix = b ns = \"http://www.google.com/2005/gml/b\" /><b:anytype i:type=\"c:string\" xmlns:c=\"http://www.w3.org/2001/XMLSchema\">" + privilegeName + "</b:anytype>" +"              </A:VALUES>" +"            </A:CONDITIONEXPRESSION>" +"          </A:CONDITIONS>" +"          <A:FILTEROPERATOR>And</A:FILTEROPERATOR>" +"          <A:FILTERS>" +"          <A:ISQUICKFINDFILTER>false</A:ISQUICKFINDFILTER>" +"        </A:FILTERS></A:CRITERIA>" +"        <A:DISTINCT>false</A:DISTINCT>" +"        <A:ENTITYNAME>privilege</A:ENTITYNAME>" +"        <A:LINKENTITIES>" +"          <A:LINKENTITY>" +"            <A:COLUMNS>" +"              <A:ALLCOLUMNS>false</A:ALLCOLUMNS>" +"              <A:COLUMNS xmlns:b=\"http://schemas.microsoft.com/2003/10/Serialization/Arrays\">" +"            </A:COLUMNS>" +"            <A:ENTITYALIAS i:nil=\"true\">" +"            <A:JOINOPERATOR>Inner</A:JOINOPERATOR>" +"            <A:LINKCRITERIA>" +"              <A:CONDITIONS>" +"              <A:FILTEROPERATOR>And</A:FILTEROPERATOR>" +"              <A:FILTERS>" +"              <A:ISQUICKFINDFILTER>false</A:ISQUICKFINDFILTER>" +"            </A:FILTERS></A:CONDITIONS></A:LINKCRITERIA>" +"            <A:LINKENTITIES>" +"              <A:LINKENTITY>" +"                <A:COLUMNS>" +"                  <A:ALLCOLUMNS>false</A:ALLCOLUMNS>" +"                  <A:COLUMNS xmlns:b=\"http://schemas.microsoft.com/2003/10/Serialization/Arrays\">" +"                </A:COLUMNS>" +"                <A:ENTITYALIAS i:nil=\"true\">" +"                <A:JOINOPERATOR>Inner</A:JOINOPERATOR>" +"                <A:LINKCRITERIA>" +"                  <A:CONDITIONS>" +"                  <A:FILTEROPERATOR>And</A:FILTEROPERATOR>" +"                  <A:FILTERS>" +"                  <A:ISQUICKFINDFILTER>false</A:ISQUICKFINDFILTER>" +"                </A:FILTERS></A:CONDITIONS></A:LINKCRITERIA>" +"                <A:LINKENTITIES>" +"                  <A:LINKENTITY>" +"                    <A:COLUMNS>" +"                      <A:ALLCOLUMNS>false</A:ALLCOLUMNS>" +"                      <A:COLUMNS xmlns:b=\"http://schemas.microsoft.com/2003/10/Serialization/Arrays\">" +"                    </A:COLUMNS>" +"                    <A:ENTITYALIAS i:nil=\"true\">" +"                    <A:JOINOPERATOR>Inner</A:JOINOPERATOR>" +"                    <A:LINKCRITERIA>" +"                      <A:CONDITIONS>" +"                        <A:CONDITIONEXPRESSION>" +"                          <A:ATTRIBUTENAME>systemuserid</A:ATTRIBUTENAME>" +"                          <A:OPERATOR>EqualUserId</A:OPERATOR>" +"                          <A:VALUES xmlns:b=\"http://schemas.microsoft.com/2003/10/Serialization/Arrays\">" +"                        </A:VALUES></A:CONDITIONEXPRESSION>" +"                      </A:CONDITIONS>" +"                      <A:FILTEROPERATOR>And</A:FILTEROPERATOR>" +"                      <A:FILTERS>" +"                      <A:ISQUICKFINDFILTER>false</A:ISQUICKFINDFILTER>" +"                    </A:FILTERS></A:LINKCRITERIA>" +"                    <A:LINKENTITIES>" +"                    <A:LINKFROMATTRIBUTENAME>roleid</A:LINKFROMATTRIBUTENAME>" +"                    <A:LINKFROMENTITYNAME>privilege</A:LINKFROMENTITYNAME>" +"                    <A:LINKTOATTRIBUTENAME>roleid</A:LINKTOATTRIBUTENAME>" +"                    <A:LINKTOENTITYNAME>systemuserroles</A:LINKTOENTITYNAME>" +"                  </A:LINKENTITIES></A:ENTITYALIAS></A:COLUMNS></A:LINKENTITY>" +"                </A:LINKENTITIES>" +"                <A:LINKFROMATTRIBUTENAME>roleid</A:LINKFROMATTRIBUTENAME>" +"                <A:LINKFROMENTITYNAME>privilege</A:LINKFROMENTITYNAME>" +"                <A:LINKTOATTRIBUTENAME>parentrootroleid</A:LINKTOATTRIBUTENAME>" +"                <A:LINKTOENTITYNAME>role</A:LINKTOENTITYNAME>" +"              </A:ENTITYALIAS></A:COLUMNS></A:LINKENTITY>" +"            </A:LINKENTITIES>" +"            <A:LINKFROMATTRIBUTENAME>privilegeid</A:LINKFROMATTRIBUTENAME>" +"            <A:LINKFROMENTITYNAME>privilege</A:LINKFROMENTITYNAME>" +"            <A:LINKTOATTRIBUTENAME>privilegeid</A:LINKTOATTRIBUTENAME>" +"            <A:LINKTOENTITYNAME>roleprivileges</A:LINKTOENTITYNAME>" +"          </A:ENTITYALIAS></A:COLUMNS></A:LINKENTITY>" +"        </A:LINKENTITIES>" +"        <A:ORDERS>" +"        <A:PAGEINFO>" +"          <A:COUNT>0</A:COUNT>" +"          <A:PAGENUMBER>0</A:PAGENUMBER>" +"          <A:PAGINGCOOKIE i:nil=\"true\">" +"          <A:RETURNTOTALRECORDCOUNT>false</A:RETURNTOTALRECORDCOUNT>" +"        </A:PAGINGCOOKIE></A:PAGEINFO>" +"        <A:NOLOCK>false</A:NOLOCK>" +"      </A:ORDERS></query>" +"    </retrievemultiple>" +"  </S:BODY>" +"</S:ENVELOPE>";
               var req = new XMLHttpRequest();
               req.open("POST", SDK.SOAP._getServerUrl(), false)
               req.setRequestHeader("Accept", "application/xml, text/xml, */*");
               req.setRequestHeader("Content-Type", "text/xml; charset=utf-8");
               req.setRequestHeader("SOAPAction", "http://schemas.microsoft.com/xrm/2011/Contracts/Services/IOrganizationService/RetrieveMultiple");
               req.send(requestXml);
               //work with the response here
			   debugger;
               var strResponse = req.responseXML.xml;
               alert(strResponse.toString());
           },
 __namespace: true
};

But I am getting a Bad Request error. Any idea why this is happening?

I used the SOAP body from this blog : http://a33ik.blogspot.in/2012/09/how-to-check-user-rights-on-client-side_7.html


Viewing all articles
Browse latest Browse all 8223

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>