I need to import data from a SQL Server table to a Collection. I’m using a Rest API and have not problems if there are very few records, but when I try to import 300 records only I get about 200.
I use this code in the page:
export async function RefreshInventario(event)
{
//Insert data from Rest Api into Collection
let idClienteSel = $w(‘#inputIdCliente’).value;
getInventarioSel(idClienteSel)
.then( AllInfo =>
{
const cantRegistros = AllInfo.lenght;
for ( var i = 0; i < AllInfo.length; i++)
{
let toInsert =
{
“idCliente”: i,
//“idCliente”: AllInfo[i].IdCliente,
“nombreCliente”: AllInfo[i].NombreCliente,
“entradaNo”: AllInfo[i].EntradaNo,
“mp_esp”: AllInfo[i].MP_Esp
};
wixData.insert("colInventario", toInsert)
.then(results =>
{
let item = results;
})
. catch (err =>
{
let errorMsg = err;
})
}
})
}
And it uses getInventarioSel from this backend function:
export async function getInventarioSel(idClienteTxt)
{
let idCliente = parseInt(idClienteTxt,10)
//https://restclaripack.azurewebsites.net/api/inventario?IdCliente=198
const url = ‘https://restclaripack.azurewebsites.net/api/inventario?IdCliente=’ + idCliente;
console.log("Url: " + url);
try
{
console.log(“fun getInventarioSel”);
let response = await fetch (url, {method: ‘get’});
let data = await response.json();
return data;
}
catch (err)
{
console.log(err)
}
}
I read that I should use async/await but I don’t understand where I have to use it.
Please somebody can help me???