locked
lookup field attributes RRS feed

  • Question

  • Hi I am a beginner in CRM and learning.

    I have a question regarding lookup fields.

    when the user selects a value from the lookup field in one form(f2) and the record related to it gets stored in form(f1).

    Now when you want to retrieve the value user selected in f2 through javascript from f1 entity, how can it be done?

    Thanks in advance.

    Wednesday, July 2, 2014 8:10 PM

Answers

  • Hi ...

    Please follow thelinks provided. Hope this solves your problem

    http://guruprasadcrm.blogspot.in/2011/04/retrieve-using-odata-and-json-in-crm.html

    http://rajeevpentyala.wordpress.com/2012/02/12/retrieve-record-using-odata-and-jquery-in-crm-2011/

    Example:

    function products()
    {
    //debugger;
    var lookUpObjectValue = new Array();

     lookUpObjectValue =Xrm.Page.getAttribute("productid").getValue();

        if (lookUpObjectValue != null)
        {
         
      var lookuptextvalue = lookUpObjectValue[0].name;
       var lookupid =  lookUpObjectValue[0].id;
     //alert(lookupid);

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

    var ODATA_ENDPOINT = serverUrl + "/XRMServices/2011/OrganizationData.svc";

    var odataSetName = "ProductSet";

        var odataSelect = ODATA_ENDPOINT + "/" + odataSetName + "(guid'" + lookupid + "')";
     $.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_account= data.d;
             
         var quantity= result_account.quantityonhand;
          var standardcost = result_account.standardcost;
           
                           Xrm.Page.getAttribute("new_quantityonhand").setValue(quantity);

                                   Xrm.Page.getAttribute("new_standardcost").setValue(standardcost);
                
            },
            error: function (XmlHttpRequest, textStatus, errorThrown) { alert('OData Select Failed: ' + odataSelect); }
        });

    }
    }

    But make sure you have to add JSON and JQuery web resources to the event library before adding this web resource which will be found in SDK.


    Prudveen D If the answer helped you, remember to mark it as answer.

    • Marked as answer by ReignFan Thursday, July 3, 2014 2:36 PM
    Thursday, July 3, 2014 5:18 AM
  • Hello ..

    "ProductSet" is my sample example where my lookup points to product entity. 

    Similarly if your lookup points to account then you have to mention "AccountSet", and if it an custom entity you need to mention same.

    Hope you understood if not come back with you doubts..

    Thank you



    Prudveen D If the answer helped you, remember to mark it as answer.

    • Marked as answer by ReignFan Thursday, July 3, 2014 5:39 PM
    Thursday, July 3, 2014 5:02 PM

All replies

  • Hi ...

    Please follow thelinks provided. Hope this solves your problem

    http://guruprasadcrm.blogspot.in/2011/04/retrieve-using-odata-and-json-in-crm.html

    http://rajeevpentyala.wordpress.com/2012/02/12/retrieve-record-using-odata-and-jquery-in-crm-2011/

    Example:

    function products()
    {
    //debugger;
    var lookUpObjectValue = new Array();

     lookUpObjectValue =Xrm.Page.getAttribute("productid").getValue();

        if (lookUpObjectValue != null)
        {
         
      var lookuptextvalue = lookUpObjectValue[0].name;
       var lookupid =  lookUpObjectValue[0].id;
     //alert(lookupid);

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

    var ODATA_ENDPOINT = serverUrl + "/XRMServices/2011/OrganizationData.svc";

    var odataSetName = "ProductSet";

        var odataSelect = ODATA_ENDPOINT + "/" + odataSetName + "(guid'" + lookupid + "')";
     $.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_account= data.d;
             
         var quantity= result_account.quantityonhand;
          var standardcost = result_account.standardcost;
           
                           Xrm.Page.getAttribute("new_quantityonhand").setValue(quantity);

                                   Xrm.Page.getAttribute("new_standardcost").setValue(standardcost);
                
            },
            error: function (XmlHttpRequest, textStatus, errorThrown) { alert('OData Select Failed: ' + odataSelect); }
        });

    }
    }

    But make sure you have to add JSON and JQuery web resources to the event library before adding this web resource which will be found in SDK.


    Prudveen D If the answer helped you, remember to mark it as answer.

    • Marked as answer by ReignFan Thursday, July 3, 2014 2:36 PM
    Thursday, July 3, 2014 5:18 AM
  • Hi Prudween,

    Thank you so much your reply, got to understand the concept.

    Is it auto generated through oData Query designer tool.

    Because writing a odataSelect looks a bit complicated and I didn't get what is var odataSetName = "ProductSet";

    Can you please let me know?

    Thanks

    Thursday, July 3, 2014 2:43 PM
  • Hello ..

    "ProductSet" is my sample example where my lookup points to product entity. 

    Similarly if your lookup points to account then you have to mention "AccountSet", and if it an custom entity you need to mention same.

    Hope you understood if not come back with you doubts..

    Thank you



    Prudveen D If the answer helped you, remember to mark it as answer.

    • Marked as answer by ReignFan Thursday, July 3, 2014 5:39 PM
    Thursday, July 3, 2014 5:02 PM
  • Thanks

    Got it!

    Thursday, July 3, 2014 5:39 PM