Asked by:
Fields not coming Across in Lookup

Question
-
I am using a Main form and I lookup to another form. I have fetch xml which takes some fields from the lookup form and carries them over to the Main form. The lookup is to a list of people and the lookup form contains Name, Address, Phone, Ref Number.
Sometimes not all the fields come across from the lookup i.e. Name and Address comes across but Phone and Ref Number doesn't.
When I close out of the form I get the following error message:
<CrmScriptErrorReport> <ReportVersion>1.0</ReportVersion> <ScriptErrorDetails> <Message>Unable to get value of the property 'text': object is null or undefined</Message> <Line>129</Line>
This error message only appears when all the fields don't carry over from the lookup form to the Main form.
Anyone any ideas why this is happening?
Thanks.
Friday, September 25, 2015 9:39 AM
All replies
-
Friday, September 25, 2015 11:11 AMModerator
-
var lookupItem = new Array; var authenticationHeader = Xrm.Page.context.getAuthenticationHeader(); lookupItem = Xrm.Page.getAttribute("applicant").getValue()[0].id; if (lookupItem != null) { var fetchXml = '<fetch version="1.0" output-format="xml-platform" mapping="logical">'; // Target Entity Name fetchXml += '<entity name="test">'; // Required Attribute fetchXml += '<attribute name="address1_line1"/>'; fetchXml += '<attribute name="address1_line2"/>'; fetchXml += '<attribute name="Phone"/>'; fetchXml += '<attribute name="RefNum"/>'; // Condition fetchXml += '<filter type="and">'; fetchXml += '<condition attribute="contactid" operator="eq" value="'+lookupItem+'" />'; fetchXml += '</filter>'; fetchXml += '</entity>'; fetchXml += '</fetch>'; var Xml = "<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\">" Xml += Xrm.Page.context.getAuthenticationHeader() Xml += "<soap:Body>"; Xml += "<Fetch xmlns=\"http://schemas.microsoft.com/crm/2007/WebServices\">"; Xml += "<fetchXml>"; Xml += _HtmlEncode(fetchXml); Xml += "</fetchXml>"; Xml += "</Fetch>"; Xml += "</soap:Body>"; Xml += "</soap:Envelope>"; //var XmlHttp = CreateXmlHttp(); //var XmlHttp = Mscrm.XmlUtil.createXmlHttp(); var XmlHttp = new ActiveXObject("Msxml2.XMLHTTP"); XmlHttp.open("POST", "/mscrmservices/2007/crmservice.asmx", false ); XmlHttp.setRequestHeader("Content-Type", "text/xml; charset=utf-8"); XmlHttp.setRequestHeader("SOAPAction", "http://schemas.microsoft.com/crm/2007/WebServices/Fetch"); XmlHttp.send(Xml); var resultDoc = loadXmlDocument(XmlHttp.responseXML.text); var resultAdd1 = resultDoc.selectNodes("//address1_line1"); var resultAdd2= resultDoc.selectNodes("//address1_line2"); var resultPhone = resultDoc.selectNodes("//Phone"); var resultRefNum = resultDoc.selectNodes("//RefNum "); // Display the retrieved values on form if (resultAdd1.length ==1) { var Add1 = Xrm.Page.data.entity.attributes.get("address1"); Add1.setValue(resultAdd1[0].text); } else { var Add1 = Xrm.Page.data.entity.attributes.get("address1"); Add1.setValue(null); } if(resultAdd2.length ==1) { var Add2 = Xrm.Page.data.entity.attributes.get("address2"); Add2.setValue(resultAdd2[0].text); } else { var Add2 = Xrm.Page.data.entity.attributes.get("address2"); Add2.setValue(null); } if(resultPhone.length==1) { var Add3 = Xrm.Page.data.entity.attributes.get("Phone"); Add3.setValue(resultAdd3[0].text); } else { var Add3 = Xrm.Page.data.entity.attributes.get("Phone"); Add3.setValue(null); } if(RefNum.length==1) { var Add4 = Xrm.Page.data.entity.attributes.get("RefNum"); Add4.setValue(resultAdd4[0].text); } else { var Add4 = Xrm.Page.data.entity.attributes.get("RefNum"); Add4.setValue(null); }
Here you go Andrii.Friday, September 25, 2015 12:34 PM -
Hello,
I believe you have to change code
if(resultPhone.length==1) { var Add3 = Xrm.Page.data.entity.attributes.get("Phone"); Add3.setValue(resultAdd3[0].text); } else { var Add3 = Xrm.Page.data.entity.attributes.get("Phone"); Add3.setValue(null); } if(RefNum.length==1) { var Add4 = Xrm.Page.data.entity.attributes.get("RefNum"); Add4.setValue(resultAdd4[0].text); } else { var Add4 = Xrm.Page.data.entity.attributes.get("RefNum"); Add4.setValue(null); }
to code:
if(resultPhone.length==1) { var Add3 = Xrm.Page.data.entity.attributes.get("Phone"); Add3.setValue(resultPhone[0].text); } else { var Add3 = Xrm.Page.data.entity.attributes.get("Phone"); Add3.setValue(null); } if(resultRefNum.length==1) { var Add4 = Xrm.Page.data.entity.attributes.get("RefNum"); Add4.setValue(resultRefNum[0].text); } else { var Add4 = Xrm.Page.data.entity.attributes.get("RefNum"); Add4.setValue(null); }
And in general. Seems that you use CRM 2011 and write code using CRM 4.0 approaches and endpoints. Just for heads up - you can forget about fetchxml and xml parsing - you have lightweight OData endpoint to use in JScript/HTML webresources - https://msdn.microsoft.com/en-us/library/gg334279.aspx
Dynamics CRM MVP
My blog- Edited by Andrii ButenkoMVP, Moderator Friday, September 25, 2015 3:05 PM
- Proposed as answer by Payman BiukaghazadehEditor Saturday, September 26, 2015 1:50 PM
- Unproposed as answer by JMcCon Monday, September 28, 2015 12:51 PM
Friday, September 25, 2015 3:03 PMModerator -
Thanks for the reply Andrii.
I tried the above but it doesn't seem to be working.
Monday, September 28, 2015 12:51 PM -
I tried this Andrii and I'm still having the same problem.Monday, September 28, 2015 3:43 PM