Answered by:
how to get data from a lookup.

Question
-
Hello to all.
how to get data from a lookup.
example:
A account have (account no, firstname, lastname) and i created a enity w/ have a lookup of the account. i want automatic load the information Firstname and lastname to my custom entity. as the lookup as my trigger......
how could do it on Onchange();
thank you....
Zosimo D. Recio Jr. Microsoft Certified (Business Management Solutions specialist)Wednesday, July 1, 2009 7:28 AM
Answers
-
The problem is the parsefloat command is mismatching what you need (I was retrieving a number). Kill the parsefloat function and it should work I think i.e. try var parsedsv = supportvaluenode.nodeTypedValue
Want to hear me talk about all things CRM? Check out my blog http://leontribe.blogspot.com/- Proposed as answer by Aarch Thursday, July 9, 2009 3:55 AM
- Marked as answer by DavidJennawayMVP, Moderator Thursday, July 30, 2009 1:47 PM
Wednesday, July 8, 2009 12:19 PM
All replies
-
Hi.
You can use following:
1. You have to retrieve identifier of contact using following script:
var contactid = crmForm.all.<you contact lookup field>.DataValue[0].id;
2. Then you have to execute call to CRM WebService to retrieve contact first and last name. How to retrieve data within CRM WebService read here .
Truth is opened the prepared mind My blog - http://a33ik.blogspot.com- Proposed as answer by HIMBAPModerator Wednesday, July 1, 2009 7:48 AM
Wednesday, July 1, 2009 7:32 AMModerator -
You can make them appear in list views out of the box but to make them appear on a detail form, you'll need jscript. So here is my code for a contract line which on the lookup to a product, brings in a custom field (new_supportvalue) from the product record. It is basically SDK code stiched together with a little bit of error capturing. hope it helps:
// Get the lookup for the productid attribute on the contract line form. lookupItem = crmForm.all.productid.DataValue; //if (lookupItem[0] != null) if (lookupItem != null) { // Display the GUID of the lookup. // alert(lookupItem[0].id); var productid = lookupItem[0].id; // Prepare variables for a product to retrieve. 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/'"+ " xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'"+ " xmlns:xsd='http://www.w3.org/2001/XMLSchema'>"+ authenticationHeader+ "<soap:Body>"+ "<Retrieve xmlns='http://schemas.microsoft.com/crm/2007/WebServices'>"+ "<entityName>product</entityName>"+ "<id>"+productid+"</id>"+ "<columnSet xmlns:q1='http://schemas.microsoft.com/crm/2006/Query' xsi:type='q1:ColumnSet'>"+ "<q1:Attributes>"+ "<q1:Attribute>new_supportvalue</q1:Attribute>"+ "</q1:Attributes>"+ "</columnSet>"+ "</Retrieve>"+ "</soap:Body>"+ "</soap:Envelope>"; // Prepare the xmlHttpObject and send the request. var xHReq = new ActiveXObject("Msxml2.XMLHTTP"); xHReq.Open("POST", "/mscrmservices/2007/CrmService.asmx", false); xHReq.setRequestHeader("SOAPAction","http://schemas.microsoft.com/crm/2007/WebServices/Retrieve"); xHReq.setRequestHeader("Content-Type", "text/xml; charset=utf-8"); xHReq.setRequestHeader("Content-Length", xml.length); xHReq.send(xml); // Capture the result. var resultXml = xHReq.responseXML; // Check for errors. var errorCount = resultXml.selectNodes('//error').length; if (errorCount != 0) { var msg = resultXml.selectSingleNode('//description').nodeTypedValue; alert(msg); } // Display the retrieved value. else { if (resultXml.selectSingleNode("//q1:new_supportvalue") != null) { var supportvaluenode = resultXml.selectSingleNode("//q1:new_supportvalue"); var parsedsv = parseFloat(supportvaluenode.nodeTypedValue); crmForm.all.price.DataValue = parsedsv; } else { crmForm.all.price.DataValue = null; } } } else { crmForm.all.price.DataValue = null; }
Leon Tribe
Want to hear me talk about all things CRM? Check out my blog
http://leontribe.blogspot.com/
Want to hear me talk about all things CRM? Check out my blog http://leontribe.blogspot.com/- Proposed as answer by Leon TribeMVP Wednesday, July 1, 2009 11:15 AM
Wednesday, July 1, 2009 11:14 AM -
Hi Leon,
i tried your code and it works great except i am not able to assign the value to the form field.
I am trying to get the mobile number of a primary contact to the account form mobile field.
i am getting the value in the variable parsedsv..but when i try tio assign to mobile number field in account it says"This control accepts only null or string value"..do u knw where am wrong??
Thanks, AarchWednesday, July 8, 2009 11:24 AM -
The problem is the parsefloat command is mismatching what you need (I was retrieving a number). Kill the parsefloat function and it should work I think i.e. try var parsedsv = supportvaluenode.nodeTypedValue
Want to hear me talk about all things CRM? Check out my blog http://leontribe.blogspot.com/- Proposed as answer by Aarch Thursday, July 9, 2009 3:55 AM
- Marked as answer by DavidJennawayMVP, Moderator Thursday, July 30, 2009 1:47 PM
Wednesday, July 8, 2009 12:19 PM -
Yes leon..the parsefloat was the reason..thanks a lot :-)
Thanks, AarchThursday, July 9, 2009 3:55 AM -
Hi,
You can retrieve all the columns available in the Lookup directly using javascript. This will not however work if you need to populate an ID (example Contact Lookup Value) field. This will allow you to retrieve the text values though.
You can refer to the following post on my blog for further details:
http://msdynamicscrmworld.blogspot.com/2009/07/crm-40-lookup-retrieve-column-values.html
Cheers!
Ashish Kapoor
Ashish Kapoor || ashish.1982@gmail.comThursday, July 9, 2009 11:31 AM