locked
Fetch XML For lookup in CRM 4.0 RRS feed

  • Question

  • Hi,

    My scenario

    I have two custom entity

    new_Product & new_Resource

    product as list of products like crm,gp etc.... & resource entity as the corresponding link for product ,it as two attributes Name(Eg.Microsoft crm 4.0) & URL(www.microsoftcrm.com)

    I have a product lookup in a form(tab1).and in tab2 i have a resource attribute.

    My requirement is whenever a product is selected from the lookup corresponding link from the resource entity should get filled in form(tab2) attribute, attribute name is new_attribute

    i have written a fetchxml its working for static value only

    My Sample code

    var lookup =crmForm.new_product.DataValue[0].name

    var fetchXml = '<fetch version="1.0" output-format="xml-platform" mapping="logical">';
      fetchXml += '<entity name="new_resource">';
      fetchXml += '<attribute name="new_name"/>';
      fetchXml += '<attribute name="new_url"/>';
      fetchXml += '<filter type="and">';
      fetchXml += '<condition attribute="new_name" operator="eq" value="Microsoft Dynamics CRM" />';
      fetchXml += '</filter>';
      fetchXml += '</entity>';
      fetchXml += '</fetch>';
      Fetch(fetchXml);

    function Fetch( xml )
    {
     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 += _HtmlEncode(xml);
      Xml += "</fetchXml>";
      Xml += "</Fetch>";
      Xml += "</soap:Body>";
      Xml += "</soap:Envelope>";

     var XmlHttp = CreateXmlHttp();
      XmlHttp.open("POST", "http://bsscrm01:5555/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 resultRecords = resultDoc.selectNodes("//new_url");  

     if( resultRecords.length == 1 )  
    {  
     crmForm.all.new_attribute.value=resultRecords[0].text;  
    }
    }

    the above script works for static values

    Instead of passing "Microsoft Dynamics CRM" For Value. iF i Pass lookup its not working

    Thanks,

    Saraswathy

    Thursday, July 29, 2010 8:27 AM

Answers

  • Hi, Saraswathy.

     

    Try to use following code:

    if (crmForm.all.new_product.DataValue != null)

    {

    var lookup =crmForm.all.new_product.DataValue[0].name;

    var fetchXml = '<fetch version="1.0" output-format="xml-platform" mapping="logical">';
      fetchXml += '<entity name="new_resource">';
      fetchXml += '<attribute name="new_name"/>';
      fetchXml += '<attribute name="new_url"/>';
      fetchXml += '<filter type="and">';
      fetchXml += '<condition attribute="new_name" operator="eq" value="'+lookup+'" />';
      fetchXml += '</filter>';
      fetchXml += '</entity>';
      fetchXml += '</fetch>';
      Fetch(fetchXml);

    function Fetch( xml )
    {
     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 += _HtmlEncode(xml);
      Xml += "</fetchXml>";
      Xml += "</Fetch>";
      Xml += "</soap:Body>";
      Xml += "</soap:Envelope>";

     var XmlHttp = CreateXmlHttp();
      XmlHttp.open("POST", "http://bsscrm01:5555/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 resultRecords = resultDoc.selectNodes("//new_url");  

     if( resultRecords.length == 1 )  
    {  
     crmForm.all.new_attribute.value=resultRecords[0].text;  
    }
    }

    }


    Truth is opened the prepared mind

    My blog (english)
    Мой блог (русскоязычный)
    Thursday, July 29, 2010 8:40 AM
    Moderator

All replies

  • Hi, Saraswathy.

     

    Try to use following code:

    if (crmForm.all.new_product.DataValue != null)

    {

    var lookup =crmForm.all.new_product.DataValue[0].name;

    var fetchXml = '<fetch version="1.0" output-format="xml-platform" mapping="logical">';
      fetchXml += '<entity name="new_resource">';
      fetchXml += '<attribute name="new_name"/>';
      fetchXml += '<attribute name="new_url"/>';
      fetchXml += '<filter type="and">';
      fetchXml += '<condition attribute="new_name" operator="eq" value="'+lookup+'" />';
      fetchXml += '</filter>';
      fetchXml += '</entity>';
      fetchXml += '</fetch>';
      Fetch(fetchXml);

    function Fetch( xml )
    {
     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 += _HtmlEncode(xml);
      Xml += "</fetchXml>";
      Xml += "</Fetch>";
      Xml += "</soap:Body>";
      Xml += "</soap:Envelope>";

     var XmlHttp = CreateXmlHttp();
      XmlHttp.open("POST", "http://bsscrm01:5555/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 resultRecords = resultDoc.selectNodes("//new_url");  

     if( resultRecords.length == 1 )  
    {  
     crmForm.all.new_attribute.value=resultRecords[0].text;  
    }
    }

    }


    Truth is opened the prepared mind

    My blog (english)
    Мой блог (русскоязычный)
    Thursday, July 29, 2010 8:40 AM
    Moderator
  • try this

    var t="SomeValue";

    fetchXml += '<condition attribute="new_name" operator="eq" value="+t+" />'";


    Mahain
    Thursday, July 29, 2010 8:44 AM
    Moderator
  • hi andriy

    Thanks for the reply i will try n let u know the result

    Thanks,
    saraswathy

    Friday, July 30, 2010 12:46 PM