Erratic

The following code update a database collection. It always work fine for me in my equipment in Colombia, but not when for the real users in UK. I really don’t know what to do! Is very urgent!!! Please help me!!!

The page code is:

export function boxButtonChoose_click(event) {
console.log(“Botón oprimido”)
let userActual = session.getItem(“sto_userActual”);
let positionSel = session.getItem(“sto_positionSelected”);
let productCodeSel = session.getItem(“sto_productCode”);
let descriptionSel = $w(“#textDescription”).text;
let priceSel = $w(‘#textPriceNum’).text;

let wrasMessageBoolSel = session.getItem(“sto_wrasMessage”);
let wrasMessageSel
if (wrasMessageBoolSel === ‘true’)
{
wrasMessageSel=1
}
else
{
wrasMessageSel=0
}

setTimeout(() => {
updateRegisterDBProductSel(userActual, descriptionSel, productCodeSel, positionSel, priceSel, wrasMessageSel)
.then(resultUpdate =>
{
console.log(“END updateRegisterDBProductSel”)

        updateTime(); 

        wixLocation.to("/question1") 
    }); 
}, 1000); 

}

export function updateRegisterDBProductSel(codUserTxtSel, descriptionSel, productCodeSelectedTxtSel, positionSelectedTxtSel, priceSelectedTxtSel, wrasVisibilitySelectedTxtSel) {
console.log(“IN updateRegisterDBProductSel”)
let codUserSel = parseInt(codUserTxtSel, 10)
let productCodeSelectedSel = parseInt(productCodeSelectedTxtSel, 10)
let descriptionSelected = descriptionSel
let positionSelectedSel = parseInt(positionSelectedTxtSel, 10)
let priceSelectedSel = parseInt(priceSelectedTxtSel, 10)
let wrasVisibilitySelectedSel = parseInt(wrasVisibilitySelectedTxtSel, 10)

//Get original record and update fields
return wixData.query(“colSurvey”)
.eq(“codUser”, codUserSel)
.find()
.then((resultDB) => {
if (resultDB.items.length > 0) {
let item = resultDB.items[0];
item.productCodeSelected = productCodeSelectedSel; // fields to be updated
item.descriptionSelected = descriptionSelected;
item.positionSelected = positionSelectedSel;
item.priceSelected = priceSelectedSel;
item.wrasVisibilitySelected = wrasVisibilitySelectedSel;

            wixData.update("colSurvey", item); 
        }  **else**  { 

// handle case where no matching items found
}
return
})
. catch ((err) => {
let errorMsg = err;
});
}

[@Arturo Villar] This is less likely to be related to users in a country and more likely to do with some other error. You have two parts of the function “updateRegisterDBProductSel” that do nothing.

One is the catch statement and the other is the else with the comment “// handle case where no matching items found”.

The best way to get started with figuring this out is to:
A. Finish writing this function & return some value that either tells your page code that it worked or throws an exception.

The code best pattern in backend code is to test for failure in your then function and throw error if you don’t get what you need. If all is well then return your call to wixData.update. This will return the Wix data result to the calling function on your page OR any exceptions. Also remove the catch from this code.
B. Add the catch you removed to the call then for your call to “updateRegisterDBProductSel” in “boxButtonChoose_click”.

This will allow you to get and process errors generated in backend code.

Thank you Steven. I’ll try your advices!

Steven, I made the changes you told me, but the problem continues! Only in UK!

It works perfect in Colombia (where I developed the siite ). Also I tested with a friend in USA and worked great. But in UK it doesn’t!!!

Hi, Arturo (great name, by the way!).

I’ll defer to others as to why doesn’t work in UK but I wanted to mention that you can simplify one aspect of your code by replacing the following (verbose) code:

  let wrasMessageSel
  if (wrasMessageBoolSel === 'true')
    {         
       wrasMessageSel=1     
    }
  else
    {
      wrasMessageSel=0     
    }

with the following (more compact) code:

  let wrasMessageSel = (wrasMessageBoolSel === 'true' ? 1 : 0);

Enjoy!

Art

What is your opinion about the problem with UK?

I really don’t know; that’s why I indicated “I’ll defer to others as to why doesn’t work in UK”.

Perhaps, Wix/Corvid could address that issue for you.

Well I am in the UK so if you point me at the url that is failing - I’ll let you know what is going on :wink:

Problem solved! The people in the UK used to have the collection opened in Live: This caused the problem! Is not possible to update the collection if this is opened :frowning:

Thank you Steven, but as I say down: Problem solved! The people in the UK used to have the collection opened in Live: This caused the problem! Is not possible to update the collection if this is opened :frowning: . It was no easy to realize that