APIs & Domo Developer

APIs & Domo Developer

Reading dataset into a custom app with Javascript

Hello. I created this customer app but no matter what I do I cannot get anything to display. I have a dataset with a few columns and I want to display those column values in the custom app. I know javascript, html, and css, but having a hard time getting anything from the dataset to display. I have included the files I created along with the output image. Any help would be appreciated. Thanks.

OutputPage.png
Tagged:

Welcome!

It looks like you're new here. Members get access to exclusive content, events, rewards, and more. Sign in or register to get started.
Sign In

Best Answers

  • Contributor
    edited May 2024 Answer ✓

    I can see that there we probably some simple CSS updates between the code, nothing was added that is hiding or modifying the HTML's classes or ids right?

    That could make the table not render, because your code is working fine for me.

    Screenshot 2024-05-14 at 1.21.44 PM.png

    ** Was this post helpful? Click 💡/💖/👍/😊 below. **
    ** If it solved your problem. Accept it as a solution! ✔️ **

    Or do you need more help? https://calendly.com/matthew-kastner/15-minute-chat
    Did I help you out? Feedback is priceless and will help me more than you know.Write a review!

  • Coach
    Answer ✓

    Here's a couple screenshots showing two different ways I'm calling the dataset. Note the difference in function(result) vs handleResult.

    image.png image.png

    ** Was this post helpful? Click Agree or Like below. **
    ** Did this solve your problem? Accept it as a solution! **

  • Contributor
    Answer ✓

    Here is a video of me hooking up the code that I sent you: https://www.loom.com/share/c8eb60962c6847db89f569e1181564d3?sid=9c876d8d-cd82-4309-9dc2-1c3a278a00cb

    And I attached an image of where you can find the uploading of a dataset.

    Group 148 (1).png


    Please 💡/💖/👍/😊 this post if you read it and found it helpful.
    Please accept the answer if it solved your problem.

    ** Was this post helpful? Click 💡/💖/👍/😊 below. **
    ** If it solved your problem. Accept it as a solution! ✔️ **

    Or do you need more help? https://calendly.com/matthew-kastner/15-minute-chat
    Did I help you out? Feedback is priceless and will help me more than you know.Write a review!

Answers

  • Contributor

    Is there a reason you are waiting for the DOMContentLoaded message?

    You shouldn't need to wait for that to be fired off.
    The below code will now call to a listed dataset:
    ———

    var domo = window.domo;
    var datasets = window.datasets;

    // Fetch the data using the pre-configured dataset alias 'DATASET0'
    var query = `/data/v1/${datasets[0]}`;
    domo
    .get(query)
    .then(function (data) {
    var tableBody = document.getElementById('dataRows');
    data.forEach(function(row) {
    var tr = document.createElement('tr');

    var td1 = document.createElement('td');
    var link = document.createElement('a');
    link.href = row.URL || '#'; // Adjust the property name as per your dataset columns
    link.textContent = row.Title || 'No Title'; // Adjust the property name as per your dataset columns
    td1.appendChild(link);
    tr.appendChild(td1);

    var td2 = document.createElement('td');
    td2.textContent = row.Desc || 'No Description'; // Adjust the property name as per your dataset columns
    tr.appendChild(td2);

    tableBody.appendChild(tr);
    });
    })
    .catch(function (error) {
    console.error("Error fetching data:", error);
    });


    ** Was this post helpful? Click 💡/💖/👍/😊 below. **
    ** If it solved your problem. Accept it as a solution! ✔️ **

    Or do you need more help? https://calendly.com/matthew-kastner/15-minute-chat
    Did I help you out? Feedback is priceless and will help me more than you know.Write a review!

  • Thank you for that. But still not getting any output

    output2.png
  • Is there a security setting that I need to update in Domo to make this work?

  • Contributor
    edited May 2024 Answer ✓

    I can see that there we probably some simple CSS updates between the code, nothing was added that is hiding or modifying the HTML's classes or ids right?

    That could make the table not render, because your code is working fine for me.

    Screenshot 2024-05-14 at 1.21.44 PM.png

    ** Was this post helpful? Click 💡/💖/👍/😊 below. **
    ** If it solved your problem. Accept it as a solution! ✔️ **

    Or do you need more help? https://calendly.com/matthew-kastner/15-minute-chat
    Did I help you out? Feedback is priceless and will help me more than you know.Write a review!

  • I got it to work! But I keep getting an error while saving it "Error Creating DomoApp". I suspect that the DATASET0 is not binded correctly to the data. I have to manually select the data every time I access the page.

    Output7.png
  • here is what I see when I first get into the app. I have to manually choose and bind the data for it to work. Where do I setup the dataset0 to bind with the data?

    dataset error.png
  • Are you saving after you select the dataset at dataset0? It looks like you are calling the dataset properly. And you've selected it. What is the warning in the triangle?

    ** Was this post helpful? Click Agree or Like below. **
    ** Did this solve your problem? Accept it as a solution! **

  • Coach
    Answer ✓

    Here's a couple screenshots showing two different ways I'm calling the dataset. Note the difference in function(result) vs handleResult.

    image.png image.png

    ** Was this post helpful? Click Agree or Like below. **
    ** Did this solve your problem? Accept it as a solution! **

    1. //This code uses the example dataset…

    2. var domo = window.domo;
    3. var datasets = window.datasets;
    4.  
    5. // get the data
    6. domo.get(`data/v1/${datasets[0]}`).then(function(result){
    7. var tableHTML = "<table><tr>";
    8. // Extract headers and make them bold
    9. var headers = Object.keys(result[0]);
    10. headers.forEach(function(header) {
    11. tableHTML += "<th><b>" + header + "</b></th>";
    12. });
    13. tableHTML += "</tr>";
    14.  
    15. // Loop through each row and populate table
    16. result.forEach(function(row) {
    17. tableHTML += "<tr>";
    18. headers.forEach(function(header) {
    19. tableHTML += "<td>" + row[header] + "</td>";
    20. });
    21. tableHTML += "</tr>";
    22. });
    23. tableHTML += "</table>";
    24.  
    25. // Link to html
    26. document.getElementById("result").innerHTML = tableHTML;
    27. });

    1. <!DOCTYPE html>
    2. <html lang="en">
    3. <body>
    4. <header>
    5. <h1>Full Dataset Test</h1>
    6. </header>
    7. <main>
    8. <div id="result"></div>
    9. </main>
    10. </body>
    11. </html>


    1. table {
    2. border-collapse: collapse;
    3. width: 100%;
    4. }
    5.  
    6. th, td {
    7. border: 1px solid black;
    8. padding: 8px;
    9. text-align: left;
    10. }
    11.  
    12. th {
    13. background-color: #4CABC5;
    14. color: white;
    15. font-weight: bold;
    16. }
    17.  
    18. td:nth-child(3) {
    19. border-left: 3px solid black;
    20. border-right: 3px solid black;
    21. background-color: #A3D4E1;
    22. }

    ** Was this post helpful? Click Agree or Like below. **
    ** Did this solve your problem? Accept it as a solution! **

  • Contributor
    Answer ✓

    Here is a video of me hooking up the code that I sent you: https://www.loom.com/share/c8eb60962c6847db89f569e1181564d3?sid=9c876d8d-cd82-4309-9dc2-1c3a278a00cb

    And I attached an image of where you can find the uploading of a dataset.

    Group 148 (1).png


    Please 💡/💖/👍/😊 this post if you read it and found it helpful.
    Please accept the answer if it solved your problem.

    ** Was this post helpful? Click 💡/💖/👍/😊 below. **
    ** If it solved your problem. Accept it as a solution! ✔️ **

    Or do you need more help? https://calendly.com/matthew-kastner/15-minute-chat
    Did I help you out? Feedback is priceless and will help me more than you know.Write a review!

Welcome!

It looks like you're new here. Members get access to exclusive content, events, rewards, and more. Sign in or register to get started.
Sign In