locked
Auto Filled values in fields below in the Form in the case of Existing Customer RRS feed

  • Question

  • Respected Sir,

    I have a Existing Customer look-up field in CASE Entity, 

    Now the requirement is when i select Existing Customer, the Details should be Auto Filled below related to Existing Customer.

    How it is possible ..?   Please HELP 

    THANKING YOU IN ADVANCE!

    Friday, August 22, 2014 10:13 AM

Answers

  • You got to retrieve the values using odata and set the values to fields on the case form.
    • Marked as answer by Goswami Amit Saturday, August 23, 2014 7:44 AM
    Friday, August 22, 2014 11:51 AM
  • function GetDetails(ProgramId) {
    /**
     * CREATED BY:     CREATED ON: 
     * FUNCTIONALITY:To retrieve the total cost of all campaigns for a particular marketing program
     * @params ProgramId 
     * @return Campaign Program Results
     */

        var serverUrl = Xrm.Page.context.getServerUrl();
        var ODATA = serverUrl + "/xrmservices/2011/OrganizationData.svc/CampaignSet?$select=TotalActualCost&$filter=biz_CampaignProgramId/Id eq guid'" + ProgramId + "'";
        var retrieve = new XMLHttpRequest();
        retrieve.open("GET", ODATA, false);
        retrieve.setRequestHeader("Accept", "application/json");
        retrieve.setRequestHeader("Content-Type", "application/json; charset=utf-8");
        retrieve.send();
        if (retrieve.readyState == 4 /* complete */) {
            if (retrieve.status == 200) {
                var retrieved = this.parent.JSON.parse(retrieve.responseText).d;
                if (retrieved.results != null) {
                    var Results = retrieved.results;
                    return Results;
                    alert(Results);
                }
            }
        }
    }

    Monday, August 25, 2014 7:20 AM
  • That is just a sample that will retrieve records from campaignset.....you gota retrieve values from contactset and that sample code does work. plz debug you will understand more.

    You will need to fetch the contact guid and then your odata query will be like this

     var ODATA = serverUrl + "/xrmservices/2011/OrganizationData.svc/AccountSet(guid'" + accountId + "')?$select=biz_DFAccountId";

    Friday, September 12, 2014 5:33 AM
  • mate,

    you are selecting only id field($select=biz_DFContactId) in your current odata query. (like you write a sql query, you have to specify the fields that you wish to see

    did you inspect the result returned by the query execution?

    regards,

    Jithesh



    Friday, September 12, 2014 9:45 AM
  • Yes dude in your odata query your not selecting the proper fields (address fields ).Please enter the query in chrome browser and you will get the names of the fields you need to retrieve and why are you using ajax,Use the template above that I provided.


    Friday, September 12, 2014 10:09 AM
  • hello mate,

    you got to step back a moment and generate the oData query first for your organization.

    1. There is a managed solution called odata query designer. This helps to build odata queries.

    http://crm2011odatatool.codeplex.com/

    install this, under settings you could see a new menu.

    use this tool to build a new query for your CRM instance and replace it with your odata query.

    except the last message, rest are all your alerts.

    alert('hello');

    will always show a message as hello.

    regards

    Jithesh


    Friday, September 12, 2014 10:41 AM

All replies

  • You got to retrieve the values using odata and set the values to fields on the case form.
    • Marked as answer by Goswami Amit Saturday, August 23, 2014 7:44 AM
    Friday, August 22, 2014 11:51 AM
  • Thanx a lot but how Sir please provide any link or something please.

    Thanx a lot again.

    Saturday, August 23, 2014 7:44 AM
  • there are a lot of samples provided with the SDK. Please check under JS folder.

    regards,

    Jithesh

    Saturday, August 23, 2014 7:51 AM
  • another option is to use xrmservicetoolkit - like the sample I gave on the following post.

    http://social.microsoft.com/Forums/en-US/d4d8b41a-c6f9-47d0-aa5c-0e704e88739b/crm-2013-writing-javascript-to-validate-entity-information-using-odata?forum=crm

    xrmservicetoolkit is a js library to help you do rest and soap service calls.

    regards,

    Jithesh

    Saturday, August 23, 2014 7:56 AM
  • thanx a lot sir but i want some Customer related attributes value from Contact Entity in the Case Entity Form attributes.

    In Case Entity there is 1 field Existing Customer which has look-up type, now the requirement is when i select Existing Customer with look-up there is some attributes below as same as in Contact Entity like :- Customer's Address, City, Department etc.. so, they are auto filled through Contact Entity's Attributes.

    Got it Sir :)

    PLEASE HELP! 

    Saturday, August 23, 2014 11:04 AM
  • thanx a lot sir but i want some Customer related attributes value from Contact Entity in the Case Entity Form attributes.

    In Case Entity there is 1 field Existing Customer which has look-up type, now the requirement is when i select Existing Customer with look-up there is some attributes below as same as in Contact Entity like :- Customer's Address, City, Department etc.. so, they are auto filled through Contact Entity's Attributes.

    Got it Sir :)

    PLEASE HELP! 


    Saturday, August 23, 2014 11:04 AM
  • function GetDetails(ProgramId) {
    /**
     * CREATED BY:     CREATED ON: 
     * FUNCTIONALITY:To retrieve the total cost of all campaigns for a particular marketing program
     * @params ProgramId 
     * @return Campaign Program Results
     */

        var serverUrl = Xrm.Page.context.getServerUrl();
        var ODATA = serverUrl + "/xrmservices/2011/OrganizationData.svc/CampaignSet?$select=TotalActualCost&$filter=biz_CampaignProgramId/Id eq guid'" + ProgramId + "'";
        var retrieve = new XMLHttpRequest();
        retrieve.open("GET", ODATA, false);
        retrieve.setRequestHeader("Accept", "application/json");
        retrieve.setRequestHeader("Content-Type", "application/json; charset=utf-8");
        retrieve.send();
        if (retrieve.readyState == 4 /* complete */) {
            if (retrieve.status == 200) {
                var retrieved = this.parent.JSON.parse(retrieve.responseText).d;
                if (retrieved.results != null) {
                    var Results = retrieved.results;
                    return Results;
                    alert(Results);
                }
            }
        }
    }

    Monday, August 25, 2014 7:20 AM
  • thanks a lot Sir,

    I am working on it :)

    Tuesday, August 26, 2014 9:35 AM
  • Sir,

    It doesn't work please help.

    Thursday, September 11, 2014 5:33 PM
  • Sir,

    It doesn't work please help.

    Thursday, September 11, 2014 5:34 PM
  • That is just a sample that will retrieve records from campaignset.....you gota retrieve values from contactset and that sample code does work. plz debug you will understand more.

    You will need to fetch the contact guid and then your odata query will be like this

     var ODATA = serverUrl + "/xrmservices/2011/OrganizationData.svc/AccountSet(guid'" + accountId + "')?$select=biz_DFAccountId";

    Friday, September 12, 2014 5:33 AM
  • Thankyou so much Sir but Sir i want to show you something please lets C the Scenario  from the beginning :

    This is my LEAD FORM :

    In this Lead Form there is Existing Customer Field which is LOOK-UP :

    NOW : When i am selecting this Contact in this LOOK-UP i want these Address Fields to Auto Populate from Contact Entity on Lead Entity Form(On the same page) Only and for this,

    My CODE is : (made this code in Web Resource and called it on the Event of Existing Customer (Look-up) Field) :

    I think now you will judge better Sir (PLEASE HELP):

    ***************************************************************************


    function getContactDetails()
    {
        var lookUpObjectValue = Xrm.Page.getAttribute("customerid").getValue();
        if ((lookUpObjectValue != null))
        {
            var lookuptextvalue = lookUpObjectValue[0].name;

            var lookupid = lookUpObjectValue[0].id;
            alert(lookupid);


        var serverUrl = Xrm.Page.context.getServerUrl();

        //The XRM OData end-point
        var ODATA_ENDPOINT = "/XRMServices/2011/OrganizationData.svc";


        var odataSetName = "ContactSet";

        var odataSelect = serverUrl + ODATA_ENDPOINT + "/" + odataSetName + "(guid'" + lookupid + "')?$select=biz_DFContactId";

        alert(odataSelect);

        $.ajax({
            type: "GET",
            contentType: "application/json; charset=utf-8",
            datatype: "json",
            url: odataSelect,
            beforeSend: function (XMLHttpRequest) { XMLHttpRequest.setRequestHeader("Accept", "application/json"); },
            success: function (data, textStatus, XmlHttpRequest) 
      {

                var result_contact= data.d;          

                             alert(result_contact.ContactId);
                            var mc_city1 = result_contact.address1_City;

                            //replace the fields with the fields on your entity

                            Xrm.Page.getAttribute("mc_city").setValue(mc_city1);

                            Xrm.Page.getAttribute("address1_city").setValue(mc_city1);
                            Xrm.Page.getAttribute("address1_line1").setValue(result_contact.address1_name);
                            Xrm.Page.getAttribute("emailaddress1").setValue(result_contact.emailaddress1);
                            Xrm.Page.getAttribute("telephone1").setValue(result_contact.address1_telephone1);
                            Xrm.Page.getAttribute("mobilephone").setValue(result_contact.mobilephone);
                            Xrm.Page.getAttribute("address1_stateorprovince").setValue(result_contact.address1_line1);
                            Xrm.Page.getAttribute("address1_postalcode").setValue(result_contact.new_postalcode);
                            Xrm.Page.getAttribute("address1_country").setValue(result_contact.new_country);      
      },
            error: function (XmlHttpRequest, textStatus, errorThrown) { alert('OData Select Failed: ' + odataSelect); }
        });

        }

       }


    Friday, September 12, 2014 8:54 AM
  • Thankyou so much Sir but Sir i want to show you something please lets C the Scenario  from the beginning :

    This is my LEAD FORM :

    In this Lead Form there is Existing Customer Field which is LOOK-UP :

    NOW : When i am selecting this Contact in this LOOK-UP i want these Address Fields to Auto Populate from Contact Entity on Lead Entity Form(On the same page) Only and for this,

    My CODE is : (made this code in Web Resource and called it on the Event of Existing Customer (Look-up) Field) :

    I think now you will judge better Sir (PLEASE HELP):

    ***************************************************************************


    function getContactDetails()
    {
        var lookUpObjectValue = Xrm.Page.getAttribute("customerid").getValue();
        if ((lookUpObjectValue != null))
        {
            var lookuptextvalue = lookUpObjectValue[0].name;

            var lookupid = lookUpObjectValue[0].id;
            alert(lookupid);


        var serverUrl = Xrm.Page.context.getServerUrl();

        //The XRM OData end-point
        var ODATA_ENDPOINT = "/XRMServices/2011/OrganizationData.svc";


        var odataSetName = "ContactSet";

        var odataSelect = serverUrl + ODATA_ENDPOINT + "/" + odataSetName + "(guid'" + lookupid + "')?$select=biz_DFContactId";

        alert(odataSelect);

        $.ajax({
            type: "GET",
            contentType: "application/json; charset=utf-8",
            datatype: "json",
            url: odataSelect,
            beforeSend: function (XMLHttpRequest) { XMLHttpRequest.setRequestHeader("Accept", "application/json"); },
            success: function (data, textStatus, XmlHttpRequest) 
      {

                var result_contact= data.d;          

                             alert(result_contact.ContactId);
                            var mc_city1 = result_contact.address1_City;

                            //replace the fields with the fields on your entity

                            Xrm.Page.getAttribute("mc_city").setValue(mc_city1);

                            Xrm.Page.getAttribute("address1_city").setValue(mc_city1);
                            Xrm.Page.getAttribute("address1_line1").setValue(result_contact.address1_name);
                            Xrm.Page.getAttribute("emailaddress1").setValue(result_contact.emailaddress1);
                            Xrm.Page.getAttribute("telephone1").setValue(result_contact.address1_telephone1);
                            Xrm.Page.getAttribute("mobilephone").setValue(result_contact.mobilephone);
                            Xrm.Page.getAttribute("address1_stateorprovince").setValue(result_contact.address1_line1);
                            Xrm.Page.getAttribute("address1_postalcode").setValue(result_contact.new_postalcode);
                            Xrm.Page.getAttribute("address1_country").setValue(result_contact.new_country);      
      },
            error: function (XmlHttpRequest, textStatus, errorThrown) { alert('OData Select Failed: ' + odataSelect); }
        });

        }

       }



    Friday, September 12, 2014 8:56 AM
  • mate,

    you are selecting only id field($select=biz_DFContactId) in your current odata query. (like you write a sql query, you have to specify the fields that you wish to see

    did you inspect the result returned by the query execution?

    regards,

    Jithesh



    Friday, September 12, 2014 9:45 AM
  • Yes dude in your odata query your not selecting the proper fields (address fields ).Please enter the query in chrome browser and you will get the names of the fields you need to retrieve and why are you using ajax,Use the template above that I provided.


    Friday, September 12, 2014 10:09 AM
  • NO Sir,

    I am getting these Errors 1 by 1 (total 3 errors).:

    After selecting the Contact Name from Contact in the Existing Customer(look-up) Field of Lead Entity Form.: FIRST ERROR

    SECOND ERROR :

    SECOND ERROR :

    Friday, September 12, 2014 10:13 AM
  • NO Sir,

    I am getting these Errors 1 by 1 (total 3 errors).:

    After selecting the Contact Name from Contact in the Existing Customer(look-up) Field of Lead Entity Form.: FIRST ERROR

    SECOND ERROR :

    SECOND ERROR :


    Friday, September 12, 2014 10:13 AM
  • AND THIS IS THIRD ERROR :

    THIRD ERROR :

    Friday, September 12, 2014 10:15 AM
  • AND THIS IS THIRD ERROR :

    THIRD ERROR :


    Friday, September 12, 2014 10:15 AM
  • "biz_DFLeadId" field doesnt exist on your entity. Please follow above comment and paste the query in google chrome.

    Friday, September 12, 2014 10:23 AM
  • hello mate,

    you got to step back a moment and generate the oData query first for your organization.

    1. There is a managed solution called odata query designer. This helps to build odata queries.

    http://crm2011odatatool.codeplex.com/

    install this, under settings you could see a new menu.

    use this tool to build a new query for your CRM instance and replace it with your odata query.

    except the last message, rest are all your alerts.

    alert('hello');

    will always show a message as hello.

    regards

    Jithesh


    Friday, September 12, 2014 10:41 AM
  • Thanx a lot sir finally i have done it but it takes a long code and process :)

    Thanks again sir!

    Tuesday, September 16, 2014 6:29 AM
  • Thanx a lot sir finally i have done it but it takes a long code and process :)

    Thanks again sir!

    Tuesday, September 16, 2014 6:29 AM