I tried to make a custom inventory 1:1 for retail setup but i get erros on this jscript can someone look in to it to offer some kind of guidence or advice

I tried to make a custom inventory 1:1 for retail setup but i get erros on this jscript can someone look in to it to offer some kind of guidence or advice

I added a column in MenuItems called Inventario = " Stock in English ",

I’m triying to update the value from that column using this script but says that doesnt find the barcode inputed
In the script I prompt asking for barcode
and then if the barcode is exist on the table ask the value to update the column Inventario

@QMcKay you are really good on scripting can you look in to it just for a second please ?

Not sure thats a great plan, editing table structure isnt reconmened…
Why not use custom product tag?

Script wise, whats the a on fist line of the if?

I’m very noob at scripting XD that was an attempt to compare if the barcode inputed is equal to the barcode obtained through the query, but i’m guessing now that is the main problem lolz

Also i have very difficult time to update the product tag value i think this script is simpler

You should not be altering the Database Table structures. There is absolutely NO good reason to do so.

Product Custom Tag is very easy to do.

I’m looking in to actions to update product tag value but i dont see an action to do so @QMcKay

Is this kind of the way to do so ?
a6

I believe ther is no action to change custom product tag. I think you can use Program Setting to store your value for ex Setting Name: Inv-Paracetamal and Setting Value: 350. You can also use database script to REPLACE custom product tag. SQL REPLACE support Regex I believe.

Agree - pretty sure there isn’t an action for it.
Product tags may well actually not be straightforward without an action or helper to update and SQL sores them in JSON which is an extra process but not imposible and doesn’t involve editing database structure.
Program setting with prefix on name for setting name could be easy option but offers no visible listing being program setting (maybe custom entity screen with/report for settings)
Product tags read, parsed, updated and saved back to db would be my route.
Although why not use inventory setup built in? There is tool for quicker 1:1 recipe creation.

is harder for user’s whom dont have any tech background, in theyre shop they are constantly changing products is an outlet store so almost every item is different
I’m trying to develope a simpler way to modify inventory, add products to inventory and add products through Jscript and SQL but maybe i can damage the DB, but right now is just for testing

Have you seen this? It was originally designed for Retail 1:1 Product/Inventory …

1 Like

I’m using your tool for some weeks it worked great but i trying to acomplish something simpler

For instance i develope this jscript to add products on the fly but it wont work, works on SQL Script but no for Jscript XD
var GroupCode = dlg.EditValue(“GRUPO;;;”);
var Barcode = dlg.EditValue(“CODIGO DE BARRAS;;;ON”,"");
var Name = dlg.EditValue(“NOMBRE;;;”);
var Inventario = dlg.EditValue(“INVENTARIO;;;ON”,"");
var ItemType = 0;
var qry1 = “SELECT TOP 1 [Id] FROM [MenuItems] ORDER BY [Id] DESC”;
var r1 = sql.Query(qry1).First;
var qry2 = “SELECT TOP 1 [Id] FROM [MenuItemPortions] ORDER BY [Id] DESC”;
var r2 = sql.Query(qry2).First;
var pname = “Normal”;
var mult = 1;
var ptag = “”;
var price = dlg.EditValue(“PRECIO DE VENTA;;;ON”,"");
var ins = “INSERT INTO [MenuItems] ([GroupCode],[Barcode],[Name],[Inventario],[ItemType]) VALUES (’”+GroupCode+"’,’"+Barcode+"’,’"+Name+"’,’"+Inventario+"’,’"+ItemType+"’)";
var r3 = sql.Query(ins).First;
var ins2 = “INSERT INTO MenuItemPortions VALUES (’”+pname+"’,’"+r1+"’,’"+mult+"’)";
var r4 = sql.Query(ins2).First;
var ins3 = “INSERT INTO MenuItemPrices VALUES(’”+r2+"’,’"+ptag+"’,’"+price+"’)"
var r5 = sql.Query(ins3).First;

function addproduct(){
return r1;
return r2;
return r3;
return r4;
return r5;
}

Font think you want the first on the exc SQL functions as insert will not return any value

@JTRTech You were saying that it would be a better way to parse Custom Tags, i was looking on the forum i found this
Any idea how it will be the value updated in the custom tag

function customtag(productname, tagname)
{
//var qry = “SELECT [CustomTags] FROM [MenuItems] WHERE [Name]=’”+productname.replace(/’/g, “\’”)+"’";

var qry = “SELECT [CustomTags] FROM [MenuItems] WHERE [Name]=’”+productname+"’";
var r = sql.Query(qry).First;
var r2 = dlg.EditValue(“INVENTARIO;;;ON”,"");
var rtag = JSON.parse®;
for(var i = 0; i < rtag.length; i++)
{
if (rtag[i].TN == tagname) return rtag[i].TV = r2;
return rtag[i].TV;
}
return 0 ;
}

The value Changed but it’s only placebo xD, wont affect the DB Custom Tag Value



I think i’m losing my mind a little XD

Looks like a lot of returns…
Perhaps the data is cashed, if you restart samba does it change?

It wont change, the script just display the value but wont update the field

sql.Query() only works for SELECT statements.

To do an INSERT or UPDATE etc. you need sql.Exec() or sql.ExecSql()

2 Likes