Get Production Information Based on ProductID

 Most of the time i found this question on microsoft forum to get product information based on productid. I have develped this code for the same requirement.

You can just paste this code on the onchange event of the product lookup. You just need to chage field names accordingly.



function GetProductInformation()


var resultXml;

var errorCount;

var msg;

var EntityName=”product”;

var xmlHttpRequest;

FetchID =crmForm.all.[name of your lookup field].DataValue[0].id

var AttributeNameList = new Array(‘vendorname’);

var authenticationHeader = GenerateAuthenticationHeader();

//Prepare the SOAP message.

var xml = “<?xml version=’1.0′ encoding=’utf-8′?>” +

“<soap:Envelope xmlns:soap=’'&#8221; +

” xmlns:xsi=’'&#8221; +

” xmlns:xsd=’’>”+

authenticationHeader +

“<soap:Body>” +

“<Retrieve xmlns=’’>&#8221; +

“<entityName>”+EntityName+”</entityName>” +

“<id>” + FetchID + “</id>” +

“<columnSet xmlns:q1=’; xsi:type=’q1:ColumnSet’>” +


for (var i = 0; i < AttributeNameList.length; i++) {

xml = xml +

‘<q1:Attribute>’ + AttributeNameList[i] + ‘</q1:Attribute>’;


xml = xml +


xml = xml +


//call function to create Soap Request to ms crm webservice

xmlHttpRequest =new ActiveXObject(“Msxml2.XMLHTTP”);

xmlHttpRequest.Open(“POST”, “/mscrmservices/2007/CrmService.asmx”, false);

xmlHttpRequest.setRequestHeader(“SOAPAction”, “;);

xmlHttpRequest.setRequestHeader(“Content-Type”, “text/xml; charset=utf-8”);

xmlHttpRequest.setRequestHeader(“Content-Length”, xml.length);


resultXml = xmlHttpRequest.responseXML;

var errorCount = resultXml.selectNodes(‘//error’).length;

if (errorCount != 0)


var msg = resultXml.selectSingleNode(‘//description’).nodeTypedValue; //Process and display the results.




if (resultXml.selectSingleNode(‘//q1:vendorname’) != null)

crmForm.all.[customfieldnametostorevendorname].DataValue = resultXml.selectSingleNode(‘//q1:vendorname’).nodeTypedValue; }}}


May be this code can help somebody at right time.

Best of luck !!!    🙂

Leave a comment

Filed under MS CRM & Javascript

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s