This project is read-only.

Retrieve Lookup value from related record

Feb 23, 2015 at 2:47 PM
I am using the XrmSvcToolkit retrieve method to get data from two entities and my results are returning as undefined.

  1. User selects a value in the lookup field on record A.
  2. XrmSvcToolkit is used to call a retrieve on the related record B.
  3. Record B contains a lookup field to related record C.
  4. I want the retrieve method to return the a value from record C and then populate a separate lookup field on record A.
Sample code:

function fSetExistingProductWithQuote() {
  var PriceQuote = Xrm.Page.getAttribute("ev_selectpricequotedetail").getValue();
      if (PriceQuote != null) {
      var quote = Xrm.Page.getAttribute("ev_selectpricequotedetail").getValue();
      var quoteid = quote[0].id;
      var results = XrmSvcToolkit.retrieve({
          entityName: "ev_pricequotedetail",
          id: quoteid,
          select: ["ev_pricequotedetailId", "ev_product_ev_pricequotedetail_itemnumber/ProductId", "ev_product_ev_pricequotedetail_itemnumber/Name"],
          expand: ["ev_product_ev_pricequotedetail_itemnumber"],
          async: false
      var Prod = results["ev_product_ev_pricequotedetail_itemnumber/ProductId"];

Can someone tell me where the code is failing? The lookup on record B is populated and record C contains the necessary data I want to return.
Feb 23, 2015 at 3:18 PM
Hi, please try to validate your query using OData Query Designer. Note that OData query is case sensitive.

Daniel Cai |
Feb 23, 2015 at 5:04 PM
Hi Daniel,

Thank you for the prompt reply.

I have used the oData Query Designer and updated my query based on the tool. I am able to execute a retrieveMultiple; however, I am still receiving an return result of "undefined".
Feb 23, 2015 at 5:06 PM
undefined means there is no value returned for that particular field. It could be one of the two situations.
  • The name of the field is not valid
  • The field has a NULL value on CRM server side
Mar 6, 2015 at 2:58 AM
Hi Daniel,

I have confirmed the field name matches the case and text in the Solution and the value on the server side is not null. I have tried multiple variations of retrieve and retrievemultiple but I am still missing something.

My three entities in question are:
  1. Order Product
  2. Price Quote Detail
  3. Product
When a user is on the Order Product form, I want to call a function onChange of the lookup field to Price Quote Detail to set the value of the Existing Product field on the Order Product form with the Product related the Price Quote Detail. I was having similar issues on other entities referencing data from the Product entity, but I was able to work around those issues with either Business Rules or a Workflow; neither of which are an option on Order Product.

I've tried another entity other as the middle linking entity, but I'm getting the same "undefined" message when I throw an alert to display the value of the lookup field I'm returning my retrieveMultiple.

Do I need to return something other than the lookup field in my result set? I'm returning the specific field with no [0].id nor [0].name included.