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.

__________________________________________________

GetProductInformation();

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=’http://schemas.xmlsoap.org/soap/envelope/'&#8221; +

” xmlns:xsi=’http://www.w3.org/2001/XMLSchema-instance'&#8221; +

” xmlns:xsd=’http://www.w3.org/2001/XMLSchema’>”+

authenticationHeader +

“<soap:Body>” +

“<Retrieve xmlns=’http://schemas.microsoft.com/crm/2007/WebServices’>&#8221; +

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

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

“<columnSet xmlns:q1=’http://schemas.microsoft.com/crm/2006/Query&#8217; xsi:type=’q1:ColumnSet’>” +

“<q1:Attributes>”;

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

xml = xml +

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

}

xml = xml +

‘</q1:Attributes></columnSet>’;

xml = xml +

“</Retrieve></soap:Body></soap:Envelope>”;

//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”, “http://schemas.microsoft.com/crm/2007/WebServices/Retrieve&#8221;);

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

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

xmlHttpRequest.send(xml);

resultXml = xmlHttpRequest.responseXML;

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

if (errorCount != 0)

{

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

}

else

{

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 !!!    🙂

Advertisements

Leave a comment

Filed under MS CRM & Javascript

Leave a Reply

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

WordPress.com Logo

You are commenting using your WordPress.com 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