//get Order Number function getOrderName(){ //Create the XML that will fetch the required info. //You can inspect this web service call using a tool called FIDDLER. var XMLRequest = "" +"<?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>" +" <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>salesorder</q1:EntityName>" +" <q1:ColumnSet xsi:type=\"q1:ColumnSet\">" +" <q1:Attributes>" +" <q1:Attribute>accountidname</q1:Attribute>" +" <q1:Attribute>name</q1:Attribute>" +" </q1:Attributes>" +" </q1:ColumnSet>" +" <q1:Distinct>false</q1:Distinct>" +" <q1:Criteria>" +" <q1:FilterOperator>And</q1:FilterOperator>" +" <q1:Conditions>" +" <q1:Condition>" +" <q1:AttributeName>name</q1:AttributeName>" +" <q1:Operator>Equal</q1:Operator>" +" <q1:Values>" +" <q1:Value xsi:type='xsd:string'>ORD0011390</q1:Value>" +"</q1:Values>" +" </q1:Condition>" +" </q1:Conditions>" +" </q1:Criteria>" +" </query>" +" </RetrieveMultiple>" +" </soap:Body>" +"</soap:Envelope>" +""; try{ //Create Http request object 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", XMLRequest.length); xmlHttpRequest.send(XMLRequest); //alert("aaa"+xmlHttpRequest.responseText); //Store the response which would be XML var Result = xmlHttpRequest.responseXML; /* The return is of type "BusinessEntity" if you were using similar code one server side. Hence we need to select node of type "BusinessEntity" In our case It should be not more one than one node */ var BusinessEntityNodes = Result.selectNodes("//RetrieveMultipleResult/BusinessEntities/BusinessEntity"); // Check If data was retrived if (BusinessEntityNodes.length != 0){ var BusinessEntityNode = BusinessEntityNodes[0]; var accountname = BusinessEntityNode.selectSingleNode("q1:accountidname"); var ordno = BusinessEntityNode.selectSingleNode("q1:name"); var accountname = (accountname == null) ? null : accountname.text; var ordno = (ordno == null) ? null :ordno .text; alert("Order"+ ordno ); } return ordno; } catch (e){ alert(e.message); } } getOrderName();
http://bproud2banindian.blogspot.co.uk/2010/09/get-full-name-of-user-by-using.html
Previously, I used the code from the above link to obtain the full name of the current user. I tried to modify it to obtain the order number which is in the Name field of the SalesOrder view. We use the Microsoft Dynamics Adapter to import
GP data into CRM and order number is mapped to the name field.
I pasted the above code into the OnLoad event of the case form which I am in the process of modifying. Right now I am just trying to display a message box to confirm this is working and then I will modify it to retrieve the data I really want so I can
auto populate some fields.The above code does not produce a message box, nothing happens. I knoe that ORD0011390 is a valid order and should return one result. Can anyone tell me what is wrong with my code?
GM