locked
Connecting to MS CRM with javascript RRS feed

  • Question

  • Hi All , I am trying to connect MS CRM with javascript . the CRM is in differnt server . so i have specified path of the CRM . when ever i am executing the method i am getting following exception Error: uncaught exception: Permission denied to call method XMLHttpRequest.open I was trying in Java before there we used to set the domain name , user name , password also . how can we set the user name and password in javascript ? var xmlHttpRequest = new ActiveXObject("Msxml2.XMLHTTP"); xmlHttpRequest.Open("POST", "http://192.10.10.129/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);
    Wednesday, August 19, 2009 3:18 PM

Answers

  •  GenerateAuthenticationHeader() is a Global function get authention info

    function  getDynamicEnitity(entityName, entityId,attributeName)
    {
        
    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>" + 
    "     <Execute xmlns=\ " http: // schemas.microsoft.com/crm/2007/WebServices\">" + 
    "       <Request xsi:type=\ " RetrieveRequest\ "  ReturnDynamicEntities=\ " true \ " > "   +  
    "         <Target xsi:type=\ " TargetRetrieveDynamic\ " > "   +  
    "           <EntityName> " + entityName + " </EntityName> "   +  
    "           <EntityId> " + entityId + " </EntityId> "   +  
    "         </Target> "   +  
    "         <ColumnSet xmlns:q1=\ " http: // schemas.microsoft.com/crm/2006/Query\" xsi:type=\"q1:ColumnSet\">" + 
    "           <q1:Attributes> "   +  
    "             <q1:Attribute> " + attributeName + " </q1:Attribute> "   +  
    "           </q1:Attributes> "   +  
    "         </ColumnSet> "   +  

    "       </Request> "   +  
    "     </Execute> "   +  
    "   </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/Execute " );
    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  getEntityPropertyValue(entityName, entityId,attributeName)
    {

    var  resultXml = getDynamicEnitity( " quote " ,entityId,attributeName);
    //  Create an XML object to parse the results.
    var  xmlDoc = new  ActiveXObject( " Microsoft.XMLDOM " );
    xmlDoc.async
    = false ;
    xmlDoc.loadXML(resultXml.xml);

    var  ret = xmlDoc.selectSingleNode( " //Property[@Name=' " + attributeName + " '] " );

    // ret.text enough for return xml;
    //
    in other case this may not enough be careful for this.
    return  ret.text;


    }

    韓建興 http://jamson.cnblogs.com
    Thursday, August 20, 2009 8:40 AM

All replies

  • I think you need to specify the username or caller name and password in the soapheader tag as follows...replace all soap:Header child tag values in following example as per your current crm system....

    hope this helps ...

    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\">" + 
    "  <soap:Header>" + 
    "    <CrmAuthenticationToken xmlns=\"http://schemas.microsoft.com/crm/2007/WebServices\">" + 
    "      <AuthenticationType xmlns=\"http://schemas.microsoft.com/crm/2007/CoreTypes\">0</AuthenticationType>" + 
    "      <OrganizationName xmlns=\"http://schemas.microsoft.com/crm/2007/CoreTypes\">MicrosoftCRM</OrganizationName>" + 
    "      <CallerId xmlns=\"http://schemas.microsoft.com/crm/2007/CoreTypes\">00000000-0000-0000-0000-000000000000</CallerId>" + 
    "    </CrmAuthenticationToken>" + 
    "  </soap:Header>" + 
    "  <soap:Body>" + 
    "    <Execute xmlns=\"http://schemas.microsoft.com/crm/2007/WebServices\">" + 
    "      <Request xsi:type=\"CloseIncidentRequest\">" + 
    "        <IncidentResolution xsi:type=\"incidentresolution\">" + 
    "          <description>resolved - description</description>" + 
    "          <incidentid type=\"incident\">d0eda8eb-324c-de11-ac71-0003ff2b38e4</incidentid>" + 
    "          <ownerid type=\"systemuser\">9bf5e0df-65c1-dc11-b67a-0003ffbb057d</ownerid>" + 
    "          <subject>resolved</subject>" + 
    "        </IncidentResolution>" + 
    "        <Status>-1</Status>" + 
    "      </Request>" + 
    "    </Execute>" + 
    "  </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/Execute");
    xmlHttpRequest.setRequestHeader("Content-Type", "text/xml; charset=utf-8");
    xmlHttpRequest.setRequestHeader("Content-Length", xml.length);
    xmlHttpRequest.send(xml);
    
    var resultXml = xmlHttpRequest.responseXML;
    alert(resultXml.xml);
    
    Wednesday, August 19, 2009 3:49 PM
  •  GenerateAuthenticationHeader() is a Global function get authention info

    function  getDynamicEnitity(entityName, entityId,attributeName)
    {
        
    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>" + 
    "     <Execute xmlns=\ " http: // schemas.microsoft.com/crm/2007/WebServices\">" + 
    "       <Request xsi:type=\ " RetrieveRequest\ "  ReturnDynamicEntities=\ " true \ " > "   +  
    "         <Target xsi:type=\ " TargetRetrieveDynamic\ " > "   +  
    "           <EntityName> " + entityName + " </EntityName> "   +  
    "           <EntityId> " + entityId + " </EntityId> "   +  
    "         </Target> "   +  
    "         <ColumnSet xmlns:q1=\ " http: // schemas.microsoft.com/crm/2006/Query\" xsi:type=\"q1:ColumnSet\">" + 
    "           <q1:Attributes> "   +  
    "             <q1:Attribute> " + attributeName + " </q1:Attribute> "   +  
    "           </q1:Attributes> "   +  
    "         </ColumnSet> "   +  

    "       </Request> "   +  
    "     </Execute> "   +  
    "   </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/Execute " );
    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  getEntityPropertyValue(entityName, entityId,attributeName)
    {

    var  resultXml = getDynamicEnitity( " quote " ,entityId,attributeName);
    //  Create an XML object to parse the results.
    var  xmlDoc = new  ActiveXObject( " Microsoft.XMLDOM " );
    xmlDoc.async
    = false ;
    xmlDoc.loadXML(resultXml.xml);

    var  ret = xmlDoc.selectSingleNode( " //Property[@Name=' " + attributeName + " '] " );

    // ret.text enough for return xml;
    //
    in other case this may not enough be careful for this.
    return  ret.text;


    }

    韓建興 http://jamson.cnblogs.com
    Thursday, August 20, 2009 8:40 AM