locked
Search a customer record using Xrm Library RRS feed

  • Question

  • I am using Xrm.page library, I am required to run a search on CRM online with "Business Phone" i.e. Telephone1 field value available, how can I use Xrm in javascript to get this task done?
    Wednesday, August 21, 2013 8:25 AM

All replies

  • you will have to create an html page in an iframe. I have given a html page which is searching contacts on 4 fields. You can modify them according to your requirement.

    Add four attributes on any entity. new_lastname new_postcode new_address_line1  new_phone

    Create a html web resource and copy paste following code into the source tab of resource.

    Create a iframe and add the URL of web resource as the url of iframe. untick ristick frame scripting

    Publish customization and test. First test this page than make changes:-

    <HTML><HEAD>
    <META charset=utf-8></HEAD>
    <BODY onload="document.getElementById('fetchinput').value = getFetchXML();resultRender.submit();">
    <SCRIPT type=text/javascript>
        function getFetchXML() {
            var strXML = '<fetch version="1.0" output-format="xml-platform" mapping="logical" distinct="false"><entity name="contact"><attribute name="contactid" /><attribute name="fullname" /><order attribute="fullname" descending="false" />';
            strXML += '<filter type="and"><filter type="and">';
            if (parent.Xrm.Page.getAttribute("new_lastname").getValue() != null) {
                strXML += '<condition attribute="lastname" operator="eq" value="' + parent.Xrm.Page.getAttribute("new_lastname").getValue() + '" />';
            }
            if (parent.Xrm.Page.getAttribute("new_postcode").getValue() != null) {
                strXML += '<condition attribute="address1_postalcode" operator="eq" value="' + parent.Xrm.Page.getAttribute("new_postcode").getValue() + '" />';
            }
            if (parent.Xrm.Page.getAttribute("new_address_line1").getValue() != null) {
                strXML += '<condition attribute="address1_line1" operator="like" value="%' + parent.Xrm.Page.getAttribute("new_address_line1").getValue() + '%" />';
            }
            if (parent.Xrm.Page.getAttribute("new_phone").getValue() != null) {
                strXML += '<filter type="or"><condition attribute="telephone2" operator="eq" value="' + parent.Xrm.Page.getAttribute("new_phone").getValue() + '" />';
                strXML += '<condition attribute="mobilephone" operator="eq" value="' + parent.Xrm.Page.getAttribute("new_phone").getValue() + '" /></filter>';
            }
            strXML += '<condition attribute="statecode" operator="eq" value="0" />';
            strXML += '</filter></filter></entity></fetch>';
            //   alert(strXML);
            return strXML;
        }
    </SCRIPT>
     
    <META content=NO-CACHE http-equiv=CACHE-CONTROL>
    <FORM id=resultRender method=post action=/AdvancedFind/fetchData.aspx><INPUT id=fetchinput type=hidden name=FetchXml> <INPUT value='<grid name="resultset" object="2" jump="lastname" select="1" icon="1" preview="1"><row name="result" id="contactid"><cell name="fullname" width="150" /><cell name="address1_line1" width="160" /><cell name="address1_line2" width="100" /><cell name="address1_postalcode" width="70" /><cell name="birthdate" width="80" /><cell name="mobilephone" width="100" /><cell name="telephone2" width="100" /><cell name="emailaddress1" width="180" /><cell name="parentcustomerid" width="100" /></row></grid>' type=hidden name=LayoutXml> <INPUT value=contact type=hidden name=EntityName> <INPUT value={00000000-0000-0000-00AA-000000666400} type=hidden name=DefaultAdvFindViewId> <INPUT value={00000000-0000-0000-00AA-000000666400} type=hidden name=ViewId> <INPUT value=1039 type=hidden name=ViewType> <INPUT value=fullname:1; type=hidden name=SortCol> <INPUT type=hidden name=UIProvider> <INPUT type=hidden name=DataProvider> </FORM></BODY></HTML>

     


    Regards Faisal

    Wednesday, August 21, 2013 5:05 PM