title: How Can I Query the Parent Record Using Javascript
body: <p><a href="https://i.stack.imgur.com/129SV.png" rel="nofollow noreferrer">Click here for picture Overview of the classes/entities</a></p>
  <p>Hi guys, It could be great if someone could re-code and help me on this.I am new in D365 and JS. Basically, how can I query the parent to case_adjustment from adjustment invoice record using JS. I have provide my current code, please help me to review it. I have try everything but so far no luck. Sorry for my unprofessional picture. But I hope you understand it and could help me to code for this situation.</p>
  <p>I have try to enable the debugger and it shows that the code cant run the adjustmentTypeLookup. and thats why it cant pass the value to retrieveRecord .Thank you.</p>
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>function adjustmentInvoiceApproveAmount(executionContext) {
      try {
          // Get the form context
          const formContext = executionContext.getFormContext();
  
          // Extract attribute values from the form
          const adjustmentAmount = formContext.getAttribute("case_adjustmentamount").getValue();
          const amountDue = formContext.getAttribute("case_amountdue").getValue();
          const adjustmentTypeLookup = formContext.getAttribute("case_adjustmenttype").getValue();
  
          // Exit as adjustmenttype is not set
          if (!adjustmentTypeLookup) return;
  
          // Extract the adjustment type record ID from the payment type lookup
          const adjustmentTypeId = adjustmentTypeLookup[0].id.substring(1, 37);
          //console.log("GUID \"case_adjustmenttype\" = " + adjustmentTypeId + " ; " + typeof adjustmentTypeId);
          //console.log(adjustmentTypeId);
           
          // Retrieve a SINGLE case_adjustmenttype based on lookup ID on form
          Xrm.WebApi.retrieveRecord("case_adjustmenttype", adjustmentTypeId, "$select=case_name").then(
              function success(adjustmentType)
            {
                  // If the payment type is credit notes then check payment amount and resit amount
                  if (adjustmentType.case_name.toLowerCase() == "Credit notes".toLowerCase()) 
                  {
                      if (adjustmentAmount &gt;= amountDue) {
                          formContext.getEventArgs().preventDefault();
                          Xrm.Navigation.openErrorDialog({message:"Payment Amount cannot be more than Resit Amount."})
                      }
                  }
                  //Otherwise do nothing
              },
              function (error) 
              {
                  console.log(error.message);
              }
          );
      } 
      catch (error) 
      {
          console.log(error);
      }
  }</code></pre>
  </div>
  </div>
  </p>