locked
MSCRM2013 javasrcipt unsupported ? RRS feed

  • Question

  • Hi I would like to ask. why the following javascript not work when I apply into my crm2013??

    function GetOpportunity(lotid) { var authenticationHeader = GenerateAuthenticationHeader(); var idXml = "" + "<?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\">" + authenticationHeader + " <soap:Body>" + " <RetrieveMultiple xmlns=\"http://schemas.microsoft.com/crm/2007/WebServices\">" + " <query xmlns:q1='http://schemas.microsoft.com/crm/2006/Query' xsi:type='q1:QueryExpression\'>" + " <q1:EntityName>opportunity</q1:EntityName>" + " <q1:ColumnSet xmlns:q1='http://schemas.microsoft.com/crm/2006/Query' xsi:type=\"q1:ColumnSet\">" + " <q1:Attributes>" + " <q1:Attribute>statecode</q1:Attribute>" + " </q1:Attributes>" + " </q1:ColumnSet>" + " <q1:Distinct>false</q1:Distinct>" + " <q1:Criteria>" + " <q1:FilterOperator>And</q1:FilterOperator>" + " <q1:Conditions>" + " <q1:Condition>" + " <q1:AttributeName>ppc_lotid</q1:AttributeName>" + " <q1:Operator>Equal</q1:Operator>" + " <q1:Values>" + " <q1:Value xsi:type=\"xsd:string\">" + lotid + "</q1:Value>" + " </q1:Values>" + " </q1:Condition>" + " </q1:Conditions>" + " </q1:Criteria>" + " </query>" + " </RetrieveMultiple>" + " </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/RetrieveMultiple"); xmlHttpRequest.setRequestHeader("Content-Type", "text/xml; charset=utf-8"); xmlHttpRequest.setRequestHeader("Content-Length",idXml.length); xmlHttpRequest.send(idXml); var resultXml = xmlHttpRequest.responseXML; var result = resultXml.getElementsByTagName('BusinessEntity'); if (result.length != 0) { var oStatusCode = result[0].selectSingleNode("q1:statecode").nodeTypedValue; if (oStatusCode == 'Won') { return true; } } return false; }

    the follow error message will prompted after I apply the javascript. issit crm2013 not supported ??

    how can I change the js to crm2013 ??

    Thank you


    Tuesday, November 18, 2014 8:31 AM

All replies

  • This is a generalised errror message. Please paste the script log here

    Regards, Saad

    Tuesday, November 18, 2014 8:37 AM
  • function GetOpportunity(lotid) {
    	var authenticationHeader = GenerateAuthenticationHeader();
    	var idXml = "" + "<?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\">" +
    	 authenticationHeader +
    	"   <soap:Body>" +
    	"   <RetrieveMultiple xmlns=\"http://schemas.microsoft.com/crm/2007/WebServices\">" +
    	"   <query xmlns:q1='http://schemas.microsoft.com/crm/2006/Query' xsi:type='q1:QueryExpression\'>" +
    	"   <q1:EntityName>opportunity</q1:EntityName>" +
    	"   <q1:ColumnSet xmlns:q1='http://schemas.microsoft.com/crm/2006/Query' xsi:type=\"q1:ColumnSet\">" +
    	"   <q1:Attributes>" +
    	"   <q1:Attribute>statecode</q1:Attribute>" +
    	"   </q1:Attributes>" +
    	"   </q1:ColumnSet>" +
    	"   <q1:Distinct>false</q1:Distinct>" +
    	"   <q1:Criteria>" +
    	"   <q1:FilterOperator>And</q1:FilterOperator>" +
    	"   <q1:Conditions>" +
    	"   <q1:Condition>" +
    	"   <q1:AttributeName>ppc_lotid</q1:AttributeName>" +
    	"   <q1:Operator>Equal</q1:Operator>" +
    	"   <q1:Values>" +
    	"   <q1:Value xsi:type=\"xsd:string\">" + lotid + "</q1:Value>" +
    	"   </q1:Values>" +
    	"   </q1:Condition>" +
    	"   </q1:Conditions>" +
    	"   </q1:Criteria>" +
    
    	"   </query>" +
    	"   </RetrieveMultiple>" +
    	"   </soap:Body>" +
    	" 	</soap:Envelope>";
    alert("bb");
    	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",idXml.length);
    	xmlHttpRequest.send(idXml);
    
    alert(xmlHttpRequest.responseXML);
    	
    	var resultXml = xmlHttpRequest.responseXML;
    	var result = resultXml.getElementsByTagName('BusinessEntity');
    
    	if (result.length != 0)
    	{
    
    		var oStatusCode = result[0].selectSingleNode("q1:statecode").nodeTypedValue;
    		if (oStatusCode == 'Won') {
    		return true;
    		}
    	}
    	
    	return false;
    
    
    }

    Check if this code works


    Regards, Saad

    Tuesday, November 18, 2014 8:43 AM
  • your code will not work because

    it's CRM 4.0 code

    it uses the CRM 4.0 endpoints (that are removed in CRM 2013)

    it uses also an ActiveX instead of XmlHttpRequest


    My blog: www.crmanswers.net - Rockstar 365 Profile

    Tuesday, November 18, 2014 9:36 AM