# No data or undefined when call from the frontend

**URL:** <https://forum.wixstudio.com/t/no-data-or-undefined-when-call-from-the-frontend/6166>\
**Category:** Ask the community\
**Tags:** question, code\
**Created:** [February 15, 2022, 11:48am UTC](https://forum.wixstudio.com/t/no-data-or-undefined-when-call-from-the-frontend/6166 "2022-02-15T11:48:41Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![youge](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/youge/32/81125_2.png) [@youge](https://forum.wixstudio.com/u/youge)\
**Post date:** [February 15, 2022, 11:48am UTC](https://forum.wixstudio.com/t/no-data-or-undefined-when-call-from-the-frontend/6166/1 "2022-02-15T11:48:41Z")

</div>

Can you provide some advice of what can cause I am not receiving the data when a promise is called from the frontend .  
When I run it from the backend, I am having the right information in return.  
So I added a step in the backend to insert those data in a collection in addition.  
Even there, I do not see the data when called from the frontend.  
Try the settimout() with no result.  
Try async/ await with no result.  
Thanks in advance

---

<div class="post-metadata">

**Author:** ![amandam](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/amandam/32/79539_2.png) [@amandam](https://forum.wixstudio.com/u/amandam)\
**Post date:** [February 15, 2022, 1:44pm UTC](https://forum.wixstudio.com/t/no-data-or-undefined-when-call-from-the-frontend/6166/2 "2022-02-15T13:44:15Z")

</div>

Hello, to help others understand your issue and offer guidance can you post the relevant code snippets you have tried in the FE/BE?

---

<div class="post-metadata">

**Author:** ![youge](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/youge/32/81125_2.png) [@youge](https://forum.wixstudio.com/u/youge)\
**Post date:** [February 15, 2022, 2:32pm UTC](https://forum.wixstudio.com/t/no-data-or-undefined-when-call-from-the-frontend/6166/3 "2022-02-15T14:32:19Z")

</div>

Here is  
Backend Code sample, because it is a complex function:

```javascript
export async function calculTarif(selChalet, selFrom, selTo, selFromNum, selToNum, isMember, isInviter, isVisiteur, selFamMbr, selFamInv, selFamVis, member) {

...
    return await wixData.get("chalets", selChalet)
        .then(rowChalet => {
            if (rowChalet !== null) {
                 typeChalet = rowChalet.typeChalet;
                return typeChalet;
            }
            return typeChalet
        })
        .then(async typeChalet => {
   ...
            while (isPeriodLeft) {
                await wixData.query("saison")
                    .le("fromNum", dateSelFromNum)
                    .gt("toNum", dateSelFromNum)
                    .find()
                    .then(async (saisons) => {
      ...
                        if (saisonCount > 0) {
                            rowsSaison = saisons.items[0];
      ...
                            if (dateSelTo <= saisonDateTo) {
...
   
                            let nbJours = await numberOfDays(lineDateFrom, lineDateTo);

                            if (isMember) {
   ...
                                let tarif = await wixData.query("tarif")
                                    .eq("saison", saisons.items[0]._id)
                                    .eq("typeChalet", typeChalet)
                                    .eq("famille", selFamMbr)
                                    .eq("group", groupSelected)
                                    // .include("saison", "typeChalet", "group")
                                    .find();

      ...
                                if (rowTarifCount > 0) {
                                    subTotal = await calculateSubTotal(rowTarif.prixDay, rowTarif.prixHebdo, rowTarif.prixMensuel, nbJours);
...
                                    periodTarif.push(tbl);
      ... }
                            }
   ...
               return periodTarif;
        })
        .then(period => {
   ... return period;
                        })
                        .catch((err) => {
                            console.error(err);
                            const response = {
                                "isOK": false,
                                "total": 0,
                                "period": [{ "?????": "null" }]
                            };
                            return period;
                        })
                })

                .catch((error) => {
                    console.error(error);
                    return response;
                });
        })
        .catch((error) => {
            console.error(error);
            return response;
        });
}

```

And the front end code:

```javascript
export async function displayTarif() {
    let dollar = new Number();
    dollar = 0;

    if (selChalet !== null && selFrom !== null && selTo !== null && selFromNum !== null && selToNum !== null && isMember !== null && isInviter !== null && isVisiteur !== null && selFamMbr !== null && selFamInv !== null && selFamVis !== null && member !== null) {
        //let response = await 
        return await calculTarif(selChalet, selFrom, selTo, selFromNum, selToNum, isMember, isInviter, isVisiteur, selFamMbr, selFamInv, selFamVis, member)
            // })
            .then((period) => {
                return period;
            })
            .then(zzz => {
                return getTarifReserv(member)
                    .then(response => {

...
                        dollar = cout;

                        if (dollar === 0 || dollar === undefined || dollar === null) {
                            $w('#tarif').text = $w('#adminTarif').text = "?";
                        } else {
                            let tmp = dollar.toLocaleString();
                            $w('#adminTarif').text = $w('#tarif').text = tmp;
                        }
                        return response;
                    })
            })
            .then((period) => {
                return SaveRqustTarifItems(selChalet, selFrom, selTo, selFromNum, selToNum, isMember, isInviter, isVisiteur, selFamMbr, selFamInv, selFamVis, member)
                    .then((period) => {
                        return period;   
                    })
            })
            .catch((err) => {
                console.error(err);
            });

    }
    if (dollar === 0 || dollar === undefined || dollar === null) {
        $w('#tarif').text = $w('#adminTarif').text = "?";
    } else {
        let tmp = dollar.toLocaleString();
        $w('#adminTarif').text = $w('#tarif').text = tmp;
    }
    return;
}

```

---

<div class="post-metadata">

**Author:** ![amandam](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/amandam/32/79539_2.png) [@amandam](https://forum.wixstudio.com/u/amandam)\
**Post date:** [February 15, 2022, 2:42pm UTC](https://forum.wixstudio.com/t/no-data-or-undefined-when-call-from-the-frontend/6166/4 "2022-02-15T14:42:16Z")

</div>

So there’s a little too much going on here for me to see exactly what is wrong, but to debug where your issue is perhaps start a little more simply.

The first issue is successfully calling your backend function from the FE, so I would pull it out of that big function and isolate it. If the data is returning then the issue is with your FE function.

Something like in your onReady just start with this and see if you can get your data:

```javascript
import { calcuTarif } from 'backend/myFunctionFile'

$w.onReady(async function () {

const results = await calcuTarif(hardcode, your, parameters,to,test);
console.log(JSON.stringify(results));
});

```

Start simply with the debugging and it will be easier to pin down the issue.

---

<div class="post-metadata">

**Author:** ![amotor](https://avatars.discourse-cdn.com/v4/letter/a/df705f/32.png) [@amotor](https://forum.wixstudio.com/u/amotor)\
**Post date:** [February 15, 2022, 6:02pm UTC](https://forum.wixstudio.com/t/no-data-or-undefined-when-call-from-the-frontend/6166/5 "2022-02-15T18:02:48Z")

</div>

Instead of returning await calculTarif try setting a variable to the result and then returning that variable at the end. For instance:

let tarif = await caclulTarif(arguments)  
… rest of code here

return tarif

---

<div class="post-metadata">

**Author:** ![youge](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/youge/32/81125_2.png) [@youge](https://forum.wixstudio.com/u/youge)\
**Post date:** [February 15, 2022, 6:05pm UTC](https://forum.wixstudio.com/t/no-data-or-undefined-when-call-from-the-frontend/6166/6 "2022-02-15T18:05:17Z")

</div>

big thank you for your advice. All this mess (on my side), was because I forget to initialize some input parameter.
