title: How to get variables from other database nodes with Cloud Function .onWrite (Firebase)
body: <p>I am trying to set some variables to send to pass into a function if a Firebase node is set to true.  I am trying to use the <code>.parent</code> and <code>.val()</code> function to set a <code>customer_id</code>, based on the documentation here: <a href="https://firebase.google.com/docs/functions/database-events" rel="nofollow noreferrer">https://firebase.google.com/docs/functions/database-events</a></p>
  
  <pre><code>exports.newCloudFunction = functions.database.ref('/user/{userId}/sources/saveSource').onWrite(event =&gt; {
  // Retrieve true/false value to verify whether card should be kept on file
  const saveSource = event.data.val();
  
  if (saveSource) {
    let snap = event.data;
    let customer_id = snap.ref.parent.child('customer_id').val();
    console.log(customer_id);
    // pass customer_id into function
  }
  </code></pre>
  
  <p>I was expecting <code>snap.ref.parent</code> to reference <code>/sources</code> and <code>.child('customer_id').val()</code> to access the value from the <code>customer_id</code> key.</p>
  
  <p>However, when I try to run this function I get the following error:</p>
  
  <pre><code>TypeError: snap.ref.parent.child(...).val is not a function
  at exports.linkCardToSquareAccount.functions.database.ref.onWrite.event (/user_code/index.js:79:56)
  at /user_code/node_modules/firebase-functions/lib/cloud-functions.js:35:20
  at process._tickDomainCallback (internal/process/next_tick.js:129:7)
  </code></pre>
  
  <p>How can I reference a node outside the scope of the original onWrite location?</p>