Pessoal,
Tenho um campo Lookup na Entidade Conta onde tenho todos os Municípios, na Entidade Conta faço um consulta a um webservice que retorna o Endereço através do CEP. Portanto, para informar o municipio que retorna da consulta do webservice preciso buscar o ID do Município para lançar o valor para o Lookup.
Utilizei o seguinte JavaScript:
function busca_municipio() {var municipio = Xrm.Page.getAttribute("name").getValue();//Xml com os parametro para consultavar fecthXml = '<fetch version="1.0" output-format="xml-platform" mapping="logical" distinct="false">'; fecthXml += '<entity name="new_municipio">'; fecthXml += '<attribute name="new_municipioid" />'; fecthXml += '<attribute name="new_municipioid" />'; fecthXml += '<attribute name="new_nomemunicipio" />'; fecthXml += '<attribute name="createdon" />'; fecthXml += '<order attribute="new_nomemunicipio" descending="false" />';//filtro por Nome do Município fecthXml += '<filter type="and">'; fecthXml += '<condition attribute="new_municipioid" operator="eq" value="' + municipio + '" />'; fecthXml += '</filter>'; fecthXml += '</entity>'; fecthXml += '</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 += GenerateAuthenticationHeader() Xml += "<soap:Body>"; Xml += "<Fetch xmlns=\"http://schemas.microsoft.com/crm/2007/WebServices\">"; Xml += "<fetchXml>"; Xml += FetchEncode(Xml); Xml += "</fetchXml>"; Xml += "</Fetch>"; Xml += "</soap:Body>"; Xml += "</soap:Envelope>";var XmlHttp = CreateXmlHttpObject(); XmlHttp.open("POST", "/mscrmservices/2007/crmservice.asmx", false); XmlHttp.setRequestHeader("SOAPAction", "http://schemas.microsoft.com/crm/2007/WebServices/Fetch"); XmlHttp.setRequestHeader("Content-Type", "text/xml; charset=utf-8"); XmlHttp.setRequestHeader("Content-Length", Xml.length); XmlHttp.send(Xml);var resultXml = xmlHttpRequest.responseXML;var id = resultXml.selectSingleNode('./id').text; alert(id[0].text); }
Retorna o seguinte erro: 'Objeto Esperado'
Alguém tem alguma dica?
Abss.