Hi all, how would I run the following javascript code in a ABMaterial web app:
I have tried the Following without any success:
I receive the following error in the console
Any ideas?
Walter
JavaScript:
var api = dtpweb.DTPWeb.getInstance();
async function updatePrinterList() {
var printerElements = document.getElementById("select-printlist");
if (api) {
var printers = await api.getPrinters({ onlyLocal: false });
printerElements.innerHTML = "";
if (printers instanceof Array && printers.length > 0) {
for (var i = 0; i < printers.length; i++) {
var item = printers[i];
var name = item.hostname && item.type !== 1 ? item.name + "@" + item.hostname : item.name;
var value = item.ip ? item.name + "@" + item.ip : item.name;
printerElements.options.add(new Option(name, value));
}
} else {
printerElements.options.add(new Option("Text", ""));
}
onPrinterChanged();
}
}
I have tried the Following without any success:
B4X:
Dim jsval As String = $"var api = dtpweb.DTPWeb.getInstance();
var printers = await api.getPrinters({ onlyLocal: false });
"$
page.ws.Eval(jsval, Null)
page.ws.Flush
I receive the following error in the console
VM3730:4 Uncaught SyntaxError: await is only valid in async functions and the top level bodies of modules
at new Function (<anonymous>)
at b4j_eval (core.4.97.min.js:97:9)
at x.<anonymous> (core.4.97.min.js:112:418)
at x.dispatchEvent (core.4.97.min.js:288:112)
at WebSocket.<anonymous> (core.4.97.min.js:214:27)
Any ideas?
Walter