0

I am not able to get the email list data from firebase. All it shows is "null".

Although the variable agent0 shows the correct selected data from the array, I can't seem to use it with the firebase reference.

How can I use one of the array values to get data from firebase?

var agent0 = agents[0];
window.alert(agent0);

var refPullEmail = firebase.database().ref("Forwarder Contact").child("All Origins").child(agent0);

refPullEmail.once("value")
    .then(function(snapshot) {

        var agentEmail_0 = snapshot.child("EmailList").val(); //return list emails

        window.alert(agentEmail_0);

    });

Database :

enter image description here

2
  • Add a screenshot of your database to the question Commented May 19, 2019 at 12:19
  • added the database all i want to get from this is the Email list Commented May 19, 2019 at 12:24

1 Answer 1

1

To retrieve the EmailList try the following:

var refPullEmail = firebase.database().ref("Forwarder Contact").child("All Origins").child("ALLIANCE");

refPullEmail.once("value")
.then(function(snapshot) {

    var agentEmail_0 = snapshot.child("EmailList").val(); //return list emails

    window.alert(agentEmail_0);

});

The above will retrieve the EmailList under node ALLIANCE.


If you want to retrieve all the EmailList under node All Origins, then try the following:

var refPullEmail = firebase.database().ref("Forwarder Contact").child("All Origins");

refPullEmail.once("value")
.then(function(snapshot) {
   snapshot.forEach(function(childSnapshot){

    var agentEmail_0 = snapshot.child("EmailList").val(); //return list emails

    window.alert(agentEmail_0);

   });
});

Here, you iterate inside the direct children of All Origins and retrieve the EmailList.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.